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.

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.

Read Also:  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 :

Read Also:  How to Integration PayPal Payment Gateway in 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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  php array remove keys keep values example
  2. Read Also:  jQuery AJAX Multiple Files Upload using PHP
  3. Read Also:  Laravel Route pass multiple Parameters Examples
  4. Read Also:  Global Config variable In Laravel 6 Example
  5. Read Also:  php array remove keys keep values
  6. Read Also:  sort query order by in codeigniter Examples
  7. Read Also:  angular 6 tutorial for beginners step by step
  8. Read Also:  PHP Filter Multidimensional Array Examples
  9. Read Also:  PHP Laravel 5.8 Image Uploading Tutorial
  10. Read Also:  Laravel 6 Eloquent ORM Delete Example
CLOSEX