learner learner - 1 year ago 122
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download