Working with arrays in PHP

Assuming you have three arrays that can contain different values ​​as follows:

$arr1 = array('1', '5', '10'); $arr2 = array('1', '3', '10'); $arr3 = array('1', '6', '10'); 

How would you divide that differently and get it like this:

 $arr1 = array('1', '10'); $arr2 = array('1', '10'); $arr3 = array('1', '10'); 

I meant that I wanted to get it as follows:

 $result = array('1', '10'); 
+4
source share
1 answer

Use array_intersect :

 <?php $arr1 = array('1', '5', '10'); $arr2 = array('1', '3', '10'); $arr3 = array('1', '6', '10'); $result = array_intersect($arr1, $arr2, $arr3); print_r($result); //now assign it back: $arr1 = $result; $arr2 = $result; $arr3 = $result; ?> 
+12
source

All Articles