Check if a value exists in a result_array()

2019-03-06 22:51发布

问题:

I have the following query ....

$query = "SELECT * FROM crescent.main_stock where transaction_type like '%Receive%' LIMIT 0,1;";
        $query = $this->db->query($query);
        $result = $query->result_array();
        if (in_array('Receive', $result)) {
            echo 'this array contains Receive';
        }

I am trying to check if a value Receive exists inside the result_array(), What is the best way to implement this? Which function should I use to check ?

回答1:

If you want to know if your query returned a value in the form of an array, you can put this at the end of your function:

$result = $query->result_array();
print_r($result);