0

I am getting this error

count(): Parameter must be an array or an object that implements Countable

CODE

if(count($settings['cols'])>0)
{
    $settings_list[] = 'cols:[' . self::prepare_reports_settings_val($settings['cols']) . ']';
}

I am getting error in if(count($settings['cols'])>0). What should I write instead of count here?

UPDATE all of the three answer are correct . is_array() worked and if($settings['cols']) also worked . I can't mark right all three . So I am writing here . Thank you all :-)

Maximious
  • 155
  • 2
  • 12
  • 4
    What exactly is the $settings['cols'], can we see a bit more of the code? – Andy Abi Haidar Sep 08 '20 at 10:36
  • Based on what little you said you could be looking for the `sizeOf()` method which gives you the number of entries present in the position `['cols']` of the array `$settings` `if(sizeOf($settings['cols'])>0)` – Berny Sep 08 '20 at 10:42

3 Answers3

4

You probably don't need to count it, as $settings['cols'] is already the number you want to compare. Just compare it directly:

if ($settings['cols'] > 0) {
BadHorsie
  • 14,135
  • 30
  • 117
  • 191
1

as you say count use for array and object . first of all you should know what is the type of your variable. so you can use

echo gettype($settings['cols']);

and see what type you have.

i think $settings['cols'] is a number that you need . you can use echo or var_dump to see it.

but if you want to get count of what you have you should do this:

1.arrays and objects : count() 2.for string : strlen() 3.for int : i think you dont need it

0
if(is_array($settings['cols']) && count($settings['cols'])>0)