我使用 CI Active Record 运行查询,结果如下:
Array (
[0] => Array ( [id_kelurahan] => 6 [id_indikator] => 8 [nilai] => 20 )
[1] => Array ( [id_kelurahan] => 6 [id_indikator] => 9 [nilai] => 20 )
)
从该结果中,我想搜索“id_kelurahan = 6”的位置并返回“nilai”的值。谢谢。
我使用 CI Active Record 运行查询,结果如下:
Array (
[0] => Array ( [id_kelurahan] => 6 [id_indikator] => 8 [nilai] => 20 )
[1] => Array ( [id_kelurahan] => 6 [id_indikator] => 9 [nilai] => 20 )
)
从该结果中,我想搜索“id_kelurahan = 6”的位置并返回“nilai”的值。谢谢。
在你的数组上做一个循环并检查它的元素。
假设您的数组存储在名为的变量中$theArray
:
foreach( $theArray as $arrayEach){
if(6 == $arrayEach['id_kelurahan']){
echo $arrayEach['nilai'];
}
}
您需要遍历数组结果,例如:
foreach($result_array as $key) {
if ( 6 == $key['id_kelurahan']) {
print $key['nilai'];
}
}
试试这个
foreach($array as $internalArray){
foreach($internalArray as $key => $value){
if($key == 'id_kelurahan' && $value == 6){
echo $internalArray['nilai'];
}
}
}