简体   繁体   中英

When I use count function in my codeigniter it gives me error

How to use count function in CodeIgniter and I am recently updating xampp 7.2 to 7.2.12

This my code I am trying like this

 print_r(count($this->input->post('disp_ch_ids')));
   exit();

It gives me this error:

A PHP Error was encountered Severity: Warning Message: count(): Parameter must be an array or an object that implements Countable Filename: dispatch_challan/DispatchChallanController.php Line Number: 24

It is unknown if 'disp_ch_ids' could actually ever be "countable", (which in this context means an array ) but assuming it is, we first need to determine if it has any value.

input::post() will return NULL if $_POST['disp_ch_ids'] does not exist. But it could be an empty string, or an array with no items.

$ch_ids = $this->input->post('disp_ch_ids');

// does $ch_ids contain anything?
if( ! empty($ch_ids))
{
    //but is it "countable"
    if(is_array($ch_ids))
    {
        //OK to count it
        print_r(count($ch_ids));
    }
    else
    {
        print_r($ch_ids);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM