蔭在PHP寫我的代碼和我的數組看起來像這樣如何通過在陣列中的多個搜索參數在PHP搜索
$arr=Array
(
[0] => Array
(
[Business_name] => 1847(Jumeirah)
[Business_id] => 1422
[Business_Locality] => Jumeirah
[Locality_id] => 2
)
[1] => Array
(
[Business_name] => 1847 Mens Salon(Trade Centre)
[Business_id] => 42
[Business_Locality] => Trade Centre
[Locality_id] => 4
)
[2] => Array
(
[Business_name] => 1847 Mens Salon(Mirdif)
[Business_id] => 1565
[Business_Locality] => Mirdif
[Locality_id] => 28
)
[3] => Array
(
[Business_name] => 1847 Mens Salon(City Walk)
[Business_id] => 494
[Business_Locality] => City Walk
[Locality_id] => 77
)
[4] => Array
(
[Business_name] => 1847 Mens Salon(Dubai Marina)
[Business_id] => 44
[Business_Locality] => Dubai Marina
[Locality_id] => 3
))
現在,如果我要得到誰擁有Locality_id = 2的數據,但如果我想要搜索locality_id = 2和locality_id = 3的數據。因此,當結果集返回時,它應該只有locality_id = 2和locality_id = 3的數據。 我該怎麼做。
這是我寫到目前爲止
function search($array, $key, $value)
{
$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
$results = array_merge($results, search($subarray, $key, $value));
}
}
return $results;
}
print_r(search($arr, 'Locality_id', '2'));
我不明白你需要 –
所以,這不是免費的編碼服務。看到你試圖做到的代碼和努力。 – Jayson
到目前爲止你已經嘗試過。顯示你的努力獲得更好的結果 –