Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP数组_intersect()-它如何处理不同的类型?_Php_Arrays_Casting_Types_Array Intersect - Fatal编程技术网

PHP数组_intersect()-它如何处理不同的类型?

PHP数组_intersect()-它如何处理不同的类型?,php,arrays,casting,types,array-intersect,Php,Arrays,Casting,Types,Array Intersect,如果我有一个基本上是各种数字的零填充字符串表示的值数组和另一个整数数组,那么数组_intersect是否仍然匹配不同类型的元素 例如,这是否有效: $arrayOne = array('0003', '0004', '0005'); $arrayTwo = array(4, 5, 6); $intersect = array_intersect($arrayOne, $arrayTwo); // $intersect would then be = "array(4, 5)" 如果没有,实

如果我有一个基本上是各种数字的零填充字符串表示的值数组和另一个整数数组,那么数组_intersect是否仍然匹配不同类型的元素

例如,这是否有效:

$arrayOne = array('0003', '0004', '0005');
$arrayTwo = array(4, 5, 6);

$intersect = array_intersect($arrayOne, $arrayTwo);

// $intersect would then be = "array(4, 5)"
如果没有,实现这一目标最有效的方法是什么?只需循环并比较,或者循环并将所有内容转换为整数,然后运行array_intersect?

$cat>test.php

<?php
$arrayOne = array('0003', '0004', '0005');
$arrayTwo = array(4, 5, 6);

$intersect = array_intersect($arrayOne, $arrayTwo);

print_r($intersect );

?>
你会得到

$php test.php

排列 [1] => 4 [2] => 5 $cat>test.php

<?php
$arrayOne = array('0003', '0004', '0005');
$arrayTwo = array(4, 5, 6);

$intersect = array_intersect($arrayOne, $arrayTwo);

print_r($intersect );

?>
你会得到

$php test.php

排列 [1] => 4 [2] => 5

来自:

在您的示例中,$intersect将是一个空数组,因为5!==005和4!==004来自:


在您的示例中,$intersect将是一个空数组,因为5!==005和4!==004

我认为应该提到string5==string5。我认为应该提到string5==string5。
Note:  Two elements are considered equal if and only if
(string) $elem1 === (string) $elem2.
In words: when the string representation is the same.