PHP Remove specific value from array

Today, We want to share with you PHP Remove specific value from array.In this post we will show you Removing Array Element and Re-Indexing in PHP, hear for How to delete an array element based on key in PHP we will give you demo and example for implement.In this post, we will learn about PHP: How to remove specific element from an array with an example.

Free Live Chat for Any Issue

PHP Remove specific value from array

There are the Following The simple About PHP Remove specific value from array Full Information With Example and source code.

Also Read This πŸ‘‰   PHP Array Remove specific value Example

As I will cover this Post with live Working example to develop remove array from multidimensional array php, so the php remove value from array if exists for this example is following below.

Remove specific value from array using php?

Using PHP array_diff()

function specific_valuew_remove($array,$value) {
  return array_diff($array, (is_array($value) ? $value : array($value)));
}
 
$products = array('php', 'laravel', 'computer', 'Iphone', 'Laptop', 'Mobile');
 
$outputs = specific_valuew_remove($products,'computer');
 
print_r($outputs);
 
// output : Array ( [0] => php [1] => laravel [3] => Iphone [4] => Laptop [5] => Mobile )

using PHP array_search()

function specific_valuew_remove(&$array,$value) {
 if(($key = array_search($value,$array)) !== false) {
       unset($array[$key]);
  }    
}
 
$products = array('php', 'laravel', 'computer', 'Iphone', 'Laptop', 'Mobile');
specific_valuew_remove($products,'php');
print_r($products);

PHP Removing/Deleteing specific value using array_keys()

	
function specific_valuew_remove($array,$value) {
 foreach (array_keys($array, $value) as $key) {
    unset($array[$key]);
 }  
  return $array;
}
 
$products = array('php', 'laravel', 'computer', 'Iphone', 'Laptop', 'Mobile','php');
$outputs = specific_valuew_remove($products,'php');
print_r($outputs);
 
// output : Array ( [1] => laravel [2] => computer [3] => Iphone [4] => Laptop [5] => Mobile ) 

Web Programming Tutorials Example with Demo

Read :

Also Read This πŸ‘‰   jQuery Ajax Upload Multiple Images using PHP

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Remove specific value from array.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Rate this post