我有这个数组
Array
(
[0] => Array
(
[completed_system_products_id] => 15
[completed_systems_id] => 9
[step_number] => 8
[product_id] => 230
[1] => Array
(
[completed_system_products_id] => 14
[completed_systems_id] => 9
[step_number] => 5
[product_id] => 127
[2] => Array
(
[completed_system_products_id] => 13
[completed_systems_id] => 9
[step_number] => 4
如何使用step_number = 4
找到数组任何想法
我试过这个
$something = array_search(4, $array);
但不是我的预期
答案 0 :(得分:3)
它在功能上并不等同(你将得到一个数组而不是一个键值),但你可以使用带有回调的array_filter。
$itemsOfInterest = array_filter ($source, function ($elem)
{
return ((isset ($elem ['step_number'])) && ($elem ['step_number'] == 4));
});
$ itemsOfInterest应该包含一个只包含符合要求的元素的数组。
答案 1 :(得分:2)
您可以通过以下功能获取ID:
function GetIdWithStep4() {
foreach ($array as $key => $value) {
if ($value['step_number'] == 4) {
return $key;
}
}
}
$something = GetIdWithStep4();