I have an array that looks like that
Array
(
[0] => Array
(
[0] => <p>How can i get the firstName values from this array? its easy with
print_r, <strong>but I want individual values</strong></p>
[1] => How can i get the firstName values from this array? its easy with
print_r, <strong>but I want individual values</strong>
)
[1] => Array
(
[0] => <p>You can do:</p>
[1] => You can do:
)
[2] => Array
(
[0] => <p>Since your array contains objects eg <code>stdClass</code>, you need to use <code>-></code> like shown above.</p>
[1] => Since your array contains objects eg <code>stdClass</code>, you need to use <code>-></code> like shown above.
)
)
how can i save the [1] values of every element in a string variable. What i want to get is
How can i get the firstName values from this array? its easy with
print_r, <strong>but I want individual values</strong> You can do: Since your array contains objects eg <code>stdClass</code>, you need to use <code>-></code> like shown above.
Update: Well the array i have in the beginning is:
Array
(
[0] => <p>try this</p>
<pre><code>foreach($x as $val)
{
echo $val->firstName;
}
</code></pre>
[1] => <p>Since you have an array of objects, you can either access each object by the array index or loop through the array to get each seperate object.</p>
<p>Once you have the object it self, you can simply access the first name property of the object.</p>
<p>Example of looping:</p>
<pre><code>foreach ( $array as $object ) {
echo $object->firstname;
}
</code></pre>
<p>Where $array is the variable containing your array.</p>
<p>Example of accessing via array index:</p>
<pre><code>echo $array[0]->firstname;
</code></pre>
<p>OR </p>
<pre><code>$obj = $array[0];
echo $obj->firstname;
</code></pre>
[2] => <p>Try this (assume <code>$a</code> is your array):</p>
<pre><code>echo $a[0]->firstname;
</code></pre>
[3] => <blockquote>
<p>How can i get the firstName values from this array? its easy with
print_r, <strong>but I want individual values</strong></p>
</blockquote>
<p>You can do:</p>
<pre><code>foreach($yourArray as $val){
echo $val->firstName;
}
</code></pre>
<p>Since your array contains objects eg <code>stdClass</code>, you need to use <code>-></code> like shown above.</p>
)
and it's named answerstack then i use:
for($j=0;$j<$answerscnt;$j++){
preg_match_all("#<p>(.*?)</p>#is",$answerstack[$j],$matches,PREG_SET_ORDER);
foreach($matches as $item){
$answerstack[$j]=$item[1]." ";
}
}
what i want to accomplish is to remove <code>
tags and the text between them from the first array but what i get is
Array
(
[0] => try this
[1] => OR
[2] => Try this (assume <code>$a</code> is your array):
[3] => Since your array contains objects eg <code>stdClass</code>, you need to use <code>-></code> like shown above.
)
<p>...</p>
from a string with regular expressions? – Kaii Mar 29 '12 at 10:46