Tuesday 14 August 2018

Remove specific value from array using php?

This post shows the possible ways to remove specific element from array based on value of the element.

Removing specific value Using array_diff()

Using this method we can remove one or more elements where using other methods we can only remove/delete one element at a given instance.

Removing specific value using array_search()

Using this method we can only remove one element at given instance. If there are two values with the same text it will remove first element only.

Removing specific value using array_keys()

If there can be multiple items with the same value, you can use array_keys to get the keys to all items as shown below.

0 comments:

Post a Comment