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 Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.