Hi all,
I'm kind of stuck on a php problem:
$a = array();
$a[] = array( "name"=>"peter", "city"=>"odense" );
$a[] = array( "name"=>"lars", "city"=>"copenhagen" );
$a[] = array( "name"=>"bo", "city"=>"aarhus" );
what I want to do is delete the array in $a that has for example a name="peter", so
the whole array that contains name peter is removed from $a
anyone know how this is done?
regards,
Peter
php arrays (call it coding if that helps)
-
- Level 2 - Grain of sand
- Posts: 23
- Joined: 11 Mar 2008, 08:56
- Contact:
Re: php arrays (call it coding if that helps)
There is only the "ugly" way of doing this. Run through the array, remember all dirty items and clean up afterwards.
^^ not tested
Code: Select all
$dirtyitems = array();
for ($i=0; $i<sizeof($a); $i++)
{
if ($a[$i][name]=="peter") $dirtyitems[]=$i;
}
foreach ($dirtyitems as $item) unset($a[$i]);