开发者

Working on arrays in PHP

Assuming that you have three arrays which might contain different values as follows.:

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

How would you strip out what's different and get it as follows?:

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

I meant I wanted to get it as follows.开发者_JAVA百科:

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


Use array_intersect function:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜