I have an a value in an array that I am not sure how to reference.
If I show the array like this:
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
print_r( $this->contents[$products_id]['attributes']); echo "<br/>";
}
I get the following output:
Array ( [5] => 115 [2] => 17 )
Array ( [5] => 115 [2] => 17 )
The value that I need is the 17.
asked May 27, 2013 at 15:17
1 Answer 1
$this->contents[$products_id]['attributes'][2]
1 Comment
Sackling
This works so thank you! And now looking at it seams obvious. I thought the 115 and the [2] were connected. doh
lang-php
list
+each
) ? Even if for this problem, you should not even think about doing this kind of actionforeach
keyword :foreach ($container as $key => $value) { /* actions */ }
(one line here, because on a SO comment, you can't paste multi line code ;). It is a loop, when on each turn,$key
will be the key of the current element (equivalent of the first argument oflist
), and$value
its value (2nd argument).