I have an array shown below and this line in my php controller:
if(count($crew_rows != 0)){
Bluehost upgraded to php7.2 and I now get the following error:
Warning: count(): Parameter must be an array or an object that implements Countable in /home2/sailwbob/public_html/skipper/public/crew.php on line 1885
How do I fix this? (without reverting to an earlier version of php)
Array
(
[0] => Array
(
[0] => Array
(
[date] => 2019年09月17日
[usr] => 1
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 09:00:00
[avalend] => 21:00:00
[sort] => 0
[ssort] => 0
)
[1] => Array
(
[date] => 2019年09月17日
[usr] => 32
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 10:00:00
[avalend] => 20:00:00
[sort] => 9
[ssort] => 1
)
[2] => Array
(
[date] => 2019年09月17日
[usr] => 76
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 09:00:00
[avalend] => 21:00:00
[sort] => 9
[ssort] => 1
)
[3] => Array
(
[date] => 2019年09月17日
[usr] => 152
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 09:00:00
[avalend] => 21:00:00
[sort] => 9
[ssort] => 1
)
[4] => Array
(
[date] => 2019年09月17日
[usr] => 155
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 11:30:00
[avalend] => 21:00:00
[sort] => 9
[ssort] => 1
)
[5] => Array
(
[date] => 2019年09月17日
[usr] => 74
[skipUsr] => 1
[user] =>
[crew] => IN
[status] => OPEN
[avalstart] => 10:00:00
[avalend] => 18:00:00
[sort] => 9
[ssort] => 9
)
[6] => Array
(
[date] => 2019年09月17日
[usr] => 25
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[7] => Array
(
[date] => 2019年09月17日
[usr] => 35
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[8] => Array
(
[date] => 2019年09月17日
[usr] => 59
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[9] => Array
(
[date] => 2019年09月17日
[usr] => 69
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[10] => Array
(
[date] => 2019年09月17日
[usr] => 126
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[11] => Array
(
[date] => 2019年09月17日
[usr] => 133
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[12] => Array
(
[date] => 2019年09月17日
[usr] => 153
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
[13] => Array
(
[date] => 2019年09月17日
[usr] => 161
[skipUsr] => 1
[user] =>
[crew] => OUT
[status] => OUT
[avalstart] => 00:00:00
[avalend] => 00:00:00
[sort] => 9
[ssort] => 9
)
)
)
asked Sep 15, 2019 at 20:40
DCR
15.8k13 gold badges62 silver badges131 bronze badges
-
1Move the comparision outside of the function call. Or remove it alltogether, 0 is falsey.Charlotte Dunois– Charlotte Dunois2019年09月15日 20:42:27 +00:00Commented Sep 15, 2019 at 20:42
1 Answer 1
You have the closing parenthesis in the wrong place in your if statement. It should look like this:
if (count($crew_rows) != 0) {
Right now, you're passing the result of $crew_rows != 0 to the count() function - a boolean, rather than an array.
answered Sep 15, 2019 at 20:43
Alex P
6,0822 gold badges26 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Markus Zeller
Even not neccessary to compare at all. If count() is > 0, the expression is true.
if (count($crew_rows)) { ... }.DCR
@Alex P, thanks. Thats be in my code for 5 years and this is the first time I got an error warning!
lang-php