arrays - PHP array_intersect() - how does it handle different types? -
if i've got array of values zerofilled string representations of various numbers , array of integers, array_intersect() still match elements of different types?
for example, work:
$arrayone = array('0003', '0004', '0005'); $arraytwo = array(4, 5, 6); $intersect = array_intersect($arrayone, $arraytwo); // $intersect = "array(4, 5)"
... , if not, efficient way accomplish this? loop through , compare, or loop through , convert integers , run array_intersect() after, or ...
$ 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
array ( )
$
so no, not. if add
foreach($arrayone $key => $value) { $arrayone[$key] = intval($value); }
you
$ php test.php
array ( [1] => 4 [2] => 5 )
Comments
Post a Comment