phpretard Posted May 30, 2009 Share Posted May 30, 2009 I have 2 arrays: I need to compair the values, pull out the values that match an then make a seperate array for matching values. Array ( [0] => 41bab296a65b71736b464f8aff39b342 [1] => 41bab296a65b71736b464f8aff39b342 [2] => 66251a6dd00d06827bb7c2e3c01bcf08 ) Array ( [0] => 07c38f09cdbd199bb39282667360b817 [1] => 66251a6dd00d06827bb7c2e3c01bcf08 [2] => 74134b63b6d0dbbf4f0157aafab505b6 ) So the new array would be: Array ( [0] => 66251a6dd00d06827bb7c2e3c01bcf08 ) The new array is what I can't figure out the code for. I hope someone can help! Thank you. Anthony Quote Link to comment https://forums.phpfreaks.com/topic/160300-solved-difficult-array-question/ Share on other sites More sharing options...
marcus Posted May 30, 2009 Share Posted May 30, 2009 Are you saying something like this? <?php $array1 = array('41bab296a65b71736b464f8aff39b342','41bab296a65b71736b464f8aff39b342','66251a6dd00d06827bb7c2e3c01bcf08'); $array2 = array('07c38f09cdbd199bb39282667360b817','66251a6dd00d06827bb7c2e3c01bcf08','74134b63b6d0dbbf4f0157aafab505b6'); foreach($array1 AS $one){ foreach($array2 AS $two){ if($one == $two){ $new = array($two); } } } print_r($new); ?> Quote Link to comment https://forums.phpfreaks.com/topic/160300-solved-difficult-array-question/#findComment-845937 Share on other sites More sharing options...
kickstart Posted May 30, 2009 Share Posted May 30, 2009 Hi Do you mean something that the php function array_intersect does? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/160300-solved-difficult-array-question/#findComment-845938 Share on other sites More sharing options...
phpretard Posted May 30, 2009 Author Share Posted May 30, 2009 Well they both work. Why was it so difficult for me? Quote Link to comment https://forums.phpfreaks.com/topic/160300-solved-difficult-array-question/#findComment-845939 Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 Well not exactly. kickstart's will work. mgallforever's code will always return an array of max length 1, or even possibly undefined. Quote Link to comment https://forums.phpfreaks.com/topic/160300-solved-difficult-array-question/#findComment-845940 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.