Forum Moderators: coopster
Warning: Cannot use a scalar value as an array in a_calendar_scheduledhours.php on line 186
Here's what I'm doing
while ($result_row = mysql_fetch_row($result)) {
$shifttypesplit = explode(" ", $result_row[0]);
$hours[shifttypesplit[1]] ++; //add them to an array, with the name as the key, and the number of shifts they're on as the value
}
The line that PHP doesn't like is $hours[shifttypesplit[1]] ++;
The problem is, I'm using the EXACT same code on another page. On this page, It's nested inside a FOREACH loop, but otherwise I'm literally doing THE EXACT same thing.
Does anyone have any ideas what's going on?
The array itself is causing the problems. I failed to notice earlier that I don't get this error message the FIRST time around the foreach() loop. It gives the error every other time after that.
So, I did what any sensible person would do and tried to unset() and empty() the array. But it didn't work. I *also* tried changing the array so that instead of $hours[$shifttypesplit[1]], it's now $hours[$key][$shifttypesplit[1]], but that didn't seem to help either.
It appears you don't really understand what's happening either. Does anyone truly know what's going on here?
If
$hours isn't causing the problem then it must be $shifttypesplit, if the explode function is passed an empty string as a delimiter it will return false, double check that there is in fact a space in between the two double-quotes. Failing that, when things aren't doing what I expect them to do putting
's [php.net] everywhere normally reveals the problem eventually. var_dump
Also make sure that your error reporting is printing Notices as well as Warnings, things like non-existent variables are Notices.
Andrew