note 76133 deleted from control-structures.foreach by tularis
| From: | tularis@php.net | Date: | Fri, 14 Nov 2014 23:32:51 +0000 |
| Subject: | note 76133 deleted from control-structures.foreach by tularis | ||
| References: | 1 | Groups: | php.notes php.notes |
| Request: | Send a blank email to php-notes+get-200915@lists.php.net to get a copy of this message | ||
Note Submitter: Luke at chaoticlogic dot net
----
Alright, I had a little error. I had one foreach() declaration, and then another foreach()
declaration.
They went:
<?php
//$connections is an array of Socket resources
foreach ($connections as $key => &$value) {
//the code here is impertinent
}
//$users is an associative array
foreach ($users as $key => &$value) {
//the code here is impertinent
}
?>
Alright, now, what error was produced as a result of this?
This one:
"Warning: Cannot use scalar value as array in filename.php on line 69."
I then realized something; the reason for this came from the fact that I used $key, and $value for
both of them in the exact same way.
As a response to this, I've developed two ways to fix this:
<?php
//add this to the end of every foreach() you use
unset($key,$value)
?>
OR
Simply use different variables for each one.