learner learner - 6 months ago 26
PHP Question

How to find a value in array and remove it by using PHP array functions

How to find a value exist in an array and how to remove it. If any php builtin array functions for doing this. After removing I need the sequential index order. any body knows please help me.


To search an element in an array, you can use array_search function and to remove an element from an array you can use unset function. Ex:

$hackers = array ('Alan Kay', 'Peter Norvig', 'Linus Trovalds', 'Larry Page');


// Search
$pos = array_search('Linus Trovalds', $hackers);

echo 'Linus Trovalds found at: ' . $pos;

// Remove from array


You can refer: http://www.php.net/manual/en/ref.array.php for more array related functions.