I have checked and it successfully goes around the array elements, and some elements do actually have some of those URLs in that I wish to delete, but they're not getting deleted. $images is actuallty a two-dimensional array now hence why I need $images. My new code: foreach($images as $key => $image) It's probably something to do with $images, as that's not the key of the array entry, only the content? Is there a way to do this without incorporating a counter?ĮDIT: Thanks guys, but now I have another problem where the array entries don't actually get deleted. So the above logic is flawed.I have a foreach loop set up to go through my array, check for a certain link, and if it finds it removes that link from the array.īut it doesn't remove the array entires. But, as discussed, isset($data) will also return false if $data was set, but was set to null. The author of this code presumably wanted to check if keyShouldBeSet was set in $data. do something here if 'keyShouldBeSet' is not set This behavior is more problematic than it might appear at first and is a common source of problems.Ĭonsider the following: $data = fetchRecordFromStorage($storage, $identifier) Unset($value) // $value no longer references $arrĬommon Mistake #2: Misunderstanding isset() behaviorĭespite its name, isset() not only returns false if an item does not exist, but also returns false for null values. To still get the benefit of using references in foreach loops without running the risk of these kinds of problems, call unset() on the variable, immediately after the foreach loop, to remove the reference e.g.: $arr = array(1, 2, 3, 4)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |