2010-08-29 7 views
4

En supposant que vous avez trois tableaux qui pourraient contenir des valeurs différentes comme suit .:de travail sur les tableaux en PHP

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

Comment Déshabillez-vous ce qui est différent et obtenir comme suit ?:

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

Je voulais dire que je voulais comme suit .:

$result = array('1', '10'); 

Répondre

12

Utiliser array_intersect Fonction:

<?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; 
?>