多维数组搜索 [英] Multidimensional array search

查看:132
本文介绍了多维数组搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个阵我怎么能拿到数组,第一个元素是128,第二个是64。

  $位置=阵列(
    阵列('64','64','home.png','www.sdsd.vf'),
    阵列('128','64','图标-building64.png','www.sdsd.vf')
);

您的帮助谢谢
温吉。


解决方案

 的foreach($位置为$位置){   如果($位置[0] =='128'和$位置[1] =='64'){
      // 就是这个!
   }}

或者你可以用 array_filter()

降其他成员

  $位置= array_filter($位置,功能($位置){   回报($位置[0] =='128'和$位置[1] =='64');});后续代码var_dump($位置);

输出

 阵列(1){[1] =>阵列(4){[0] =>串(3)128[1] =>字符串(2)64[2] =>串(19)图标building64.png[3] =>串(11)www.sdsd.vf}}

看到它

From this array how could I get that array which first element is 128 and the second is 64.

$positions = array(
    array('64','64','home.png','www.sdsd.vf'),
    array('128','64','icon-building64.png','www.sdsd.vf')
);

Thanks for your help Ungi.

解决方案

foreach($positions as $position) {

   if ($position[0] == '128' AND $position[1] == '64') {
      // This is it!
   }

}

Or you could drop the other members with array_filter().

$positions = array_filter($positions, function($position) {

   return ($position[0] == '128' AND $position[1] == '64');

});

var_dump($positions);

Output

array(1) { [1]=> array(4) { [0]=> string(3) "128" [1]=> string(2) "64" [2]=> string(19) "icon-building64.png" [3]=> string(11) "www.sdsd.vf" } } 

See it.

这篇关于多维数组搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆