查找在一维数组中所在
$arr = ['a','b','c'];
print_r(array_search(trim(‘b’), $arr)));
二维
$a = [];
$a[] = ['a' => 'a1', 'b' => 'b1', 'c' => 'c1'];
$a[] = ['a' => 'a2', 'b' => 'b2', 'c' => 'c2'];
$a[] = ['a' => 'a3', 'b' => 'b3', 'c' => 'c3'];
$a[] = ['a' => 'a4', 'b' => 'b4', 'c' => 'c4'];
$a[] = ['a' => 'a5', 'b' => 'b5', 'c' => 'c5'];
$a[] = ['a' => 'a6', 'b' => 'b6', 'c' => 'c6'];
$a[] = ['a' => 'a7', 'b' => 'b7', 'c' => 'c7'];
$a[] = ['a' => 'a8', 'b' => 'b8', 'c' => 'c8'];
$a[] = ['a' => 'a9', 'b' => 'b9', 'c' => 'c9'];
$a[] = ['a' => 'a10', 'b' => 'b10', 'c' => 'c10'];
print_r(['数组' => $a[array_search('b2', array_column($a, 'b'))], '健值' => array_search('b2', array_column($a, 'b'))]);
exit;
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
一颗大萝北
本文地址: PHP通过关键字查找一/二维数组中所在的位置,array_search与array_column
本文地址: PHP通过关键字查找一/二维数组中所在的位置,array_search与array_column