Getting specific data out of a 2D array..

im confused - and google has made me more confused.
i have a array and would like to return the value of the cells in a row that match a certian critera.
so lets say my $array looks like this

array(2) { [0]=> array(2) { ["id"]=> string(7) "100" ["name"]=> string(2) "joe" } [1]=> array(2) { ["id"]=> string(7) "101" ["name"]=> string(2) "mike" } }

I want to get the value of name for a certain id… how can i do that? iknow this is not the right syntax but i want to

print "NAME 101 =".$array[id=101];

If you know what the array key is, you could simply:

[php]echo $myarray[1][‘name’][/php]
…would output ‘mike’.

Or you could loop through the array and check the values along the way:

[php]

$myArray = array(
array(id => 100, name=>‘joe’),
array(id => 101, name=>‘mike’));

foreach ($myArray as $array => $value) {
if ($value[‘id’] == 100) {
echo $value[‘name’] . PHP_EOL;
}
}
[/php]

Shrugs… hope that helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service