desithugg Posted August 20, 2006 Share Posted August 20, 2006 umm i want to check if all the values in $array2 exist in $array1.And ouput something depending on if they exist or no.ive tried "in_array","array_search","array_key_exists"[code]<?php$a1 = array(1, 2, 3, 4, 5, 6);$a2 = array(1, 2, 3, 4, 5);if(in_array($a2, $a1)){echo"right";}else{echo"wrong";} ?> [/code]but none of them seem to work Link to comment https://forums.phpfreaks.com/topic/18114-array/ Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 Use array_intersect (http://www.php.net/array_intersect) or array_diff (http://www.php.net/array_diff).[code]$a1 = array(1, 2, 3, 4, 5, 6);$a2 = array(1, 2, 3, 4, 5);if(count(array_intersect($a2, $a1)) == count($a2)) { echo"right";} else { echo"wrong";} if (count(array_diff($a2, $a1)) == 0) { echo"right";} else { echo"wrong";} [/code] Link to comment https://forums.phpfreaks.com/topic/18114-array/#findComment-77615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.