开发者

array question filter

开发者 https://www.devze.com 2023-02-25 17:34 出处:网络
Array( [MainArray]=>Array ( [myarray] => Array ( [0] => Array ( [id]开发者_开发技巧 => 1234
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;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消