Remove element from Array

Remove element from array
array_diff($arr1, $arr2)
array_diff_key($arr1, $arr2)

<?php
$a1 = array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>4);
$a2 = array('a'=>'', 'c'=>'');
$a3 = array(1, 2, 4);

$result = array_diff_key($a1, $a2);
print_r($result);

$result = array_diff($a1, $a3);
print_r($result);
?>

Output

Array ( [b] => 2 [d] => 4 )
Array ( [c] => 3 ) 
This entry was posted in Array Helper Functions, Useful PHP Functions. Bookmark the permalink.

2 Responses to Remove element from Array

  1. Great site. A lot of useful information here. I’m sending it to some friends!

  2. I’d have to comply with you here. Which is not something I typically do! I really like reading a post that will make people think. Also, thanks for allowing me to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *


*