在数组中搜索键并从查询结果中返回值[关闭]

I have run my query with CI Active Record, and these is the result:

Array (
    [0] => Array ( [id_kelurahan] => 6 [id_indikator] => 8 [nilai] => 20 )
    [1] => Array ( [id_kelurahan] => 6 [id_indikator] => 9 [nilai] => 20 )
)

From that results, i want to search, 'where "id_kelurahan=6"' and return value of 'nilai'. Thanks.

Do a loop on your array and check for it's element.

Assuming your array is stored in variable called $theArray:

foreach( $theArray as $arrayEach){
    if(6 == $arrayEach['id_kelurahan']){
        echo $arrayEach['nilai'];
    }
}

You need to iterate over the array result like:

foreach($result_array as $key) {
  if ( 6 == $key['id_kelurahan']) {
     print $key['nilai'];
  }
}

Try this

foreach($array as $internalArray){
    foreach($internalArray as $key => $value){
        if($key == 'id_kelurahan' && $value == 6){
            echo $internalArray['nilai'];
        }
    }
}