View Single Post
Old 03-31-2009, 04:22 PM   #1 (permalink)
benton
The Contributor
 
Join Date: Apr 2008
Posts: 78
Thanks: 0
benton is on a distinguished road
Default How to delete array element in function

I'm trying to delete an array element in a function. The manual for unset says to use $GLOBALS but that isn't working for some reason. The following is basically what I am doing. But when I run it, the original array has not been changed. Would someone please point out my mistake?
PHP Code:
function DeleteElement($id$myArray)
{
  for (
$i=0$i count($myArray); ++$i)
  {
     if (
$id == $myArray[$i]['id'])
     {  
        unset(
$GLOBALS["myArray[$i]"]);
     }
  }
}          

$myArray 
 Array
(
    [
0] => Array
        (
            [
id] => 1988
        
)

    [
1] => Array
        (
            [
id] => 3444
        
)
}

DeleteElement(1988$myArray); 
benton is offline  
Reply With Quote