in_array() php returning false all round, always

alphy

I get an array of data from a MySql database:

Array ( 
    [0] => Array ( [upload_status] => 0 ) 
    [1] => Array ( [upload_status] => 0 ) 
    [2] => Array ( [upload_status] => 0 )
    [3] => Array ( [upload_status] => 0 )
    [4] => Array ( [upload_status] => 0 )
    [5] => Array ( [upload_status] => 0 )
    [6] => Array ( [upload_status] => 0 )
    [7] => Array ( [upload_status] => 1 )
    [8] => Array ( [upload_status] => 0 ) 
    [9] => Array ( [upload_status] => 0 ) 
    [10] => Array ( [upload_status] => 0 ) 
    [11] => Array ( [upload_status] => 1 ) 
    [12] => Array ( [upload_status] => 1 ) 
    [13] => Array ( [upload_status] => 1 ) 
) 

I want to check if 0 exists in the array.

I'm using this code, but in_array() returns false, despite the fact I can see the zeros in the above array.

$query = $this
    ->db
    ->select('upload_status')
    ->where('lab_ref_no',$labref)
    ->get('sample_issuance')
    ->result_array();

    print_r($query);

    if (in_array('1', $query)) {
        echo 'true';
    } else {
        echo'false';
    }
Ayaz

in_array() search containing value of array, in your case your result have array of array, so you need loop over the array and put your syntax between the loop like this:

$query= $this->db->select('upload_status')->where('lab_ref_no',$labref)->get('sample_issuance')->result_array();
    print_r($query);
    foreach($query as $arr) {
    if(in_array('1', $arr)){
        echo 'true';
    }else{
        echo'false';
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related