Organizational Research By

Surprising Reserch Topic

Question:how to used array_intersect in order to sort an array arbitrarly



asked Sep 13, 2013 in PHP by rajesh
edited Sep 12, 2013
+1 vote
63 views



Related Hot Questions

2 Answers

0 votes

 

relatively easy way to strictly intersect keys and values recursively without array key reordering,
simple recursive function examples please use this : 
 
function array_intersect_recursive($array1, $array2) 
{ 
  foreach($array1 as $key => $value) 
  { 
    if (!isset($array2[$key])) 
    { 
      unset($array1[$key]); 
    } 
    else 
    { 
      if (is_array($array1[$key])) 
      { 
        $array1[$key] = array_intersect_recursive($array1[$key], $array2[$key]); 
      } 
      elseif ($array2[$key] !== $value) 
      { 
        unset($array1[$key]); 
      } 
    } 
  } 
  return $array1; 
} 
?>
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013
0 votes

 

$a = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'height', 'nine', 'ten'); 
$b = array('four', 'one', 'height', 'five') 
var_dump(array_intersect($a, $b); 
?> 
 
will output: 
 
0 => 'one' 
1 => 'four' 
2 => 'five' 
3 => 'height' 
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...