array question filter
Array(
[MainArray]=>Array
(
[myarray] => Array
(
[0] => Array
(
[id]开发者_开发技巧 => 1234
[url] => google.com
)
[1] => Array
(
[id] => 675677
[url] => stackoverflow.com
)
[2] => Array
(
[id] => 234234
[url] => test.com
)
)
)
)
what i want is to choose the url that meets the id so if id is 1234, url should be google.com
I have this code
foreach($MainArray['myarray'] as $arr){
$url = $arr['url'];
}
but it gives me all three. I need to filter them thanks
foreach($MainArray['myarray'] as $arr)
{
if ($arr['id'] == 1234)
{
$url = $arr['url'];
break;
}
}
精彩评论