我如何在数组 php 中找到数据
How i can find data in array php
我在 php 中有这样的数据数组,
0 =>
"data" =>
0 =>
"id_data": "P-1234",
"name_data": "data 0 warga 1"
1 =>
"id_data": "P-1235",
"name_data": "data 0 warga 2"
1 =>
"data" =>
0 =>
"id_data": "O-1134",
"name_data": "data 1 warga 1"
1 =>
"id_data": "O-1135",
"name_data": "data 1 warga 2"
2 =>
"id_data": "O-1136",
"name_data": "data 1 warga 3"
如何在 php 中找到数据 id_data O-1135?
谢谢你^^
$arr = [
0 => [
"data" =>[
0 => [ "id_data"=>"P-1234", "name_data"=>"data 0 warga 1"],
1 => ["id_data"=> "P-1235","name_data"=> "data 0 warga 2"]
]
],
1 => [
"data" => [
0 => ["id_data"=> "O-1134","name_data"=> "data 1 warga 1"],
1 => ["id_data"=> "O-1135","name_data"=> "data 1 warga 2"],
2 => ["id_data"=> "O-1136", "name_data"=> "data 1 warga 3"],
]
]
];
function find_value_from_arr($arr, $findVal){
foreach($arr as $childArr){
if(( $indx = array_search( $findVal, array_column($childArr['data'], 'id_data')) ) !== FALSE){
return $childArr['data'][$indx];
}
}
return false;
}
print_r(find_value_from_arr($arr,'O-1135'));
我在 php 中有这样的数据数组,
0 =>
"data" =>
0 =>
"id_data": "P-1234",
"name_data": "data 0 warga 1"
1 =>
"id_data": "P-1235",
"name_data": "data 0 warga 2"
1 =>
"data" =>
0 =>
"id_data": "O-1134",
"name_data": "data 1 warga 1"
1 =>
"id_data": "O-1135",
"name_data": "data 1 warga 2"
2 =>
"id_data": "O-1136",
"name_data": "data 1 warga 3"
如何在 php 中找到数据 id_data O-1135? 谢谢你^^
$arr = [
0 => [
"data" =>[
0 => [ "id_data"=>"P-1234", "name_data"=>"data 0 warga 1"],
1 => ["id_data"=> "P-1235","name_data"=> "data 0 warga 2"]
]
],
1 => [
"data" => [
0 => ["id_data"=> "O-1134","name_data"=> "data 1 warga 1"],
1 => ["id_data"=> "O-1135","name_data"=> "data 1 warga 2"],
2 => ["id_data"=> "O-1136", "name_data"=> "data 1 warga 3"],
]
]
];
function find_value_from_arr($arr, $findVal){
foreach($arr as $childArr){
if(( $indx = array_search( $findVal, array_column($childArr['data'], 'id_data')) ) !== FALSE){
return $childArr['data'][$indx];
}
}
return false;
}
print_r(find_value_from_arr($arr,'O-1135'));