code_junkie

PHP array_intersect() - how does it handle different types?

Nov 12th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. $arrayOne = array('0003', '0004', '0005');
  2. $arrayTwo = array(4, 5, 6);
  3.  
  4. $intersect = array_intersect($arrayOne, $arrayTwo);
  5.  
  6. // $intersect would then be = "array(4, 5)"
  7.  
  8. <?php
  9. $arrayOne = array('0003', '0004', '0005');
  10. $arrayTwo = array(4, 5, 6);
  11.  
  12. $intersect = array_intersect($arrayOne, $arrayTwo);
  13.  
  14. print_r($intersect );
  15.  
  16. ?>
  17.  
  18. foreach($arrayOne as $key => $value)
  19. {
  20. $arrayOne[$key] = intval($value);
  21. }
  22.  
  23. Note: Two elements are considered equal if and only if
  24. (string) $elem1 === (string) $elem2.
  25. In words: when the string representation is the same.
Add Comment
Please, Sign In to add comment