PHP Arrays diff -


having $age = array("peter"=>"35", "ben"=>"37", "joe"=>"43"); $age2 = array("peter"=>"peter", "ben"=>"ben");

i want output like: $age = array("peter"=>"35", "ben"=>"37"); // without joe , same index

so want compare $age1 , $age2 , remove $age1 entry isn't in $age2? use array_diff_key() so:

$missingelements = array_diff_key($age2, $age1);  foreach($missingelements $element) { // each element not in both arrays     $index = $age1.indexof($element);      unset($age1[$index]); }  var_dump($age1); // print on screen 

this php function compares key of 2 arrays , returns difference. loop on each element returned function , remove them $age1;


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -