06-25-2009, 09:19 PM
|
#7 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by tech
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
)
|
|
|
|