Reputation: 1229
In codeigniter, in my controller file, I fetch data from model. To validate the results I use foreach loop and there is no problem. But instead of using foreach I want to use in_array() to control if variable is in database result array or not . Here is code :
function _remap($method,$params = array()){
//in construct, I use $this->model
if (isset($params[0])) {
$this->db->distinct('*****');
$this->db->from('*****');
$this->db->where('****',****);
$query = $this->db->get();
if (in_array($params[0],$query->results())) {
echo "in_array works";
}
}
But not echoing anything. How can I do it?Thanks.
Upvotes: 0
Views: 978
Reputation: 2346
I would suggest to write a helper method, that does the job you want and returns True or False. Information on how to do it can be found here
Upvotes: 0
Reputation: 1582
The in_array is just to be used for only checking a value in the value-list
e.g. array("Mac", "NT", "Irix", "Linux");
in_array wont work for your situation, because it returns object array.
Upvotes: 1