Seems strange I can’t find an answer to this, but here goes:
This:
foreach ($stuffs as $stuffRow) {
foreach ($stuffRow as $stuff) {
if($stuff=== null){
unset($stuff);
}
}
}
is not working.
I know I shouldn’t say “isn’t working”, but that’s all I’ve got. The if condition works; I’ve tested it. However, when I apply unset, the key=>value is still there.
Note: PHP 5.3
Many thanks in advance!
While this might work (i never do it this way and not tested it):
If i remember correctly, passing by reference isn’t a good idea in foreachs (but can’t remember why, might have been in the php doc somewhere, maybe someone can clarify in the comments, but i think it’s because foreach works on a copy of the array and passing a reference passes the reference to the copy, not the original, though that is just an educated guess). Instead, try this.
The reason your code didn’t work by the way is because foreach loops iterate over a COPY of your array.