我有這樣的陣列名爲$結果PHP搜索鍵在多維數組和返回值
Array ([0] => Array ([location] => DNM Room (N) [maxdac] => 12.0 [mindac] => 2.0 [avgdac] => 7.00000) [1] => Array ([location] => DNM Room (S) [maxdac] => 1.0 [mindac] => 1.0 [avgdac] => 1.00000) [2] => Array ([location] => Feeder Cabinet (N) [maxdac] => 20.0 [mindac] => 20.0 [avgdac] => 20.00000) [3] => Array ([location] => Feeder Cabinet (S) [maxdac] => 10.0 [mindac] => 10.0 [avgdac] => 10.00000) [4] => Array ([location] => FM Vault (N) [maxdac] => 10.0 [mindac] => 10.0 [avgdac] => 10.00000) [5] => Array ([location] => FM Vault (S) [maxdac] => 5.0 [mindac] => 5.0 [avgdac] => 5.00000) [6] => Array ([location] => FMLCTA [maxdac] => 1.0 [mindac] => 1.0 [avgdac] => 1.00000) [7] => Array ([location] => FMSA (N) [maxdac] => 2.0 [mindac] => 2.0 [avgdac] => 2.00000) [8] => Array ([location] => FMSA (S) [maxdac] => 0.1 [mindac] => 0.1 [avgdac] => 0.10000) [9] => Array ([location] => FPER [maxdac] => 3.0 [mindac] => 2.0 [avgdac] => 2.25000) [10] => Array ([location] => FT Room (N) [maxdac] => 0.1 [mindac] => 0.1 [avgdac] => 0.10000) [11] => Array ([location] => Moderator Room [maxdac] => 20.0 [mindac] => 7.0 [avgdac] => 14.25000) [12] => Array ([location] => PAER [maxdac] => 2.0 [mindac] => 1.0 [avgdac] => 1.57500) [13] => Array ([location] => Passage [maxdac] => 3.0 [mindac] => 1.0 [avgdac] => 1.62500) [14] => Array ([location] => Pump Room [maxdac] => 35.0 [mindac] => 20.0 [avgdac] => 27.50000) [15] => Array ([location] => RAB [maxdac] => 1.0 [mindac] => 1.0 [avgdac] => 1.00000) [16] => Array ([location] => RB Sump [maxdac] => 0.1 [mindac] => 0.1 [avgdac] => 0.10000) [17] => Array ([location] => SFSB [maxdac] => 0.0 [mindac] => 0.0 [avgdac] => 0.00000) [18] => Array ([location] => West Passage [maxdac] => 3.0 [mindac] => 0.5 [avgdac] => 1.42500))
我要搜索上述陣列中的[位置] =「FPER」,並獲得價值鍵[maxdac]。嘗試了幾個選項,沒有任何工作。不熟悉數組。任何方法
選中此選項
foreach ($array as $key => $value) {
if($value['location']=='FPER'){echo $value['maxdac'];}
}
我得到價值3.0
是否有可能使用上述循環函數內部和不同位置的值?
例如
function getstat($location, $param){
foreach ($array as $key => $value) {
if($value['location']==$location){return $value[$param];}
}
}
$myvalue=getstat('FPER', 'maxdac');
echo $myvalue;
上述功能不工作。似乎$ location和$ param在foreach中是不知道的。
任何建議請求
首先格式的問題.. –