View Single Post
Old 03-31-2009, 05:34 PM   #2 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Well...that's not good. I don't know who told you this, but it's completely wrong. The reason is not found in the code, hower, but in the PHP engine itself. It instructs functions that take as arguments arrays, strings, integers,etc. (not objects since PHP5), to make a copy of the original variable and use that when it does stuff with it in the function body. That's why GLOBALS didn't work. You didn't even need them. All you needed to do was declare the function parameter as a reference, not as a variable:

PHP Code:
function myFunction(&$array)
{
    for(
$i 0$i count($array); $i++)
    {
        if(
condition) unset($array[$i]);
    }

I don't see why you would need this function to delete an element of the array, since you can do it right in place,where you need it. It's unefficient what you do. Here's a better replacement code for that function:

PHP Code:
if(array_key_exists($i$myArray) === true && $id == $myArray[$i]['id']) unset($myArray[$i]); 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote