View Single Post
Old 06-25-2009, 09:19 PM   #7 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by tech View Post
please help me to write a code to delete an element from an array where i don't know the index position of an element
Maybe I'm missing something (which is quite possible!) but here is a way to delete an element from an array by specifying the value (not the index) to be deleted. It'll happily delete multiple elements if there are more than one of the specified value.

PHP Code:
$array = array('a''b''c''d');
foreach (
array_keys($array'b'TRUE) as $key)
{
    unset(
$array[$key]);
}
print_r($array); 
Which outputs something like:
Code:
Array
(
    [0] => a
    [2] => c
    [3] => d
)
Salathe is offline  
Reply With Quote