findParent() function find array. There could be one array or more than one.
Now I want to make if statement depends on the number of array.
How can I make if statement using the number of array?
function findParent($order_id){
...
$Q = $this->db->get('omc_order_item');
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[] = $row;
}
}
...
return $data;
}
I tried this, but it does not work.
function deleteitem($order_id){
$childless = $this->MOrders->findParent($order_id);
if ($childless<2){
$data['childlessorder']= $this->MOrders->findParent($order_id);
...
It must be checking if $childless is less than 2.
How can I change it so that it will check the number of array is 1 (can be less than 2, doesn’t it?)
If you mean number of arrays then
From your example it looks like the
findParent()function returns an array of arrays. To compare against the number of arrays contained within the resulting array you would use thecount(array())function.It returns the number of array items within the array passed as its argument.
For instance
would output 2
For documentation see the php.net/count page.