Re: Re: How do I remove an array element from within a recursive function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daevid Vincent wrote:
I tried that and it still doesn't work. I even tried this hardcore
"test":

public static final function removeMenuItems(&$menuItems, $removeArray)
{
    foreach($menuItems as &$value)
    {
        unset($value);
    }
}

You don't unset the value, you unset the key.

<?php

$items = array('menu1', 'menu2', 'menu3');

echo "Before:\n";
print_r($items);

foreach ($items as $_menuKey => $value) {
	if ($value == 'menu2') {
		unset($items[$_menuKey]);
	}
}

echo "After:\n";
print_r($items);


$ php test.php
Before:
Array
(
    [0] => menu1
    [1] => menu2
    [2] => menu3
)
After:
Array
(
    [0] => menu1
    [2] => menu3
)

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux