当前位置: 首页 > php > 正文

$userdb = array(
    0 => array(
            'uid' => 100,
            'name' => 'Sandra Shush',
            'url' => 'urlof100'
        ),
 
    1 => array(
            'uid' => 5465,
            'name' => 'Stefanie Mcmohn',
            'pic_square' => 'urlof100'
        ),
 
    2 => Array(
            'uid' => 40489,
            'name' => 'Michael',
            'pic_square' => 'urlof40489'
        )
);
 
$found_key = array_search(40489, array_column($userdb, 'uid'));
/**
    如果$userdb很大,建议使用一个变量,避免搜索每个元素时都调用array_column()
    $uid = array_column($userdb, 'uid');
    $found_key = array_search(40489, $uid);
 */
var_dump($found_key);

php利用array_search与array_column实现二维数组查找:等您坐沙发呢!

发表评论

gravatar

? razz sad evil ! smile oops grin eek shock ??? cool lol mad twisted roll wink idea arrow neutral cry mrgreen

快捷键:Ctrl+Enter