Trying to process an array and remove a specific associative array in a larger array set. The code I have now works in removing the specific sections locally, within the for loop, but doesn’t effect the original $cursor array.
foreach($cursor as $key) {
foreach($key as $value => $k){
if ($value == 'user'){
unset($k['confinfo']);
}
}
}
Is it a GLOBAL variable problem? How to unset the original variable?
Iterate over the original array by reference:
It’s important to note than whenever you do this, it’s a very good idea to follow the loop with an
unsetto destroy the reference:Personally I find this a little ugly (par for the course in PHP), but this way you eliminate the risk of reusing the name
$keylater on and causing all sorts of “interesting” effects.