vcivilen Posted March 10, 2008 Share Posted March 10, 2008 I have two arrays: $arr1 = {1,2,3,4,5,6,7,8} $arr2 = {0,3,9,10,12,14,16} How can I find the same value between them and return the ouput array: $outputarr = {3,9} ----------- Other problems: Two string $str1 = "1,2,3,4,5,6,7,8"; $str2 = "0,3,9,10,12,14,16"; how can I get $stroutput = "3,9"; ------------ I think can be use "for" or "while..do.."... but is there any quicker method ? Link to comment https://forums.phpfreaks.com/topic/95434-help-me-to-compare-two-string/ Share on other sites More sharing options...
soycharliente Posted March 10, 2008 Share Posted March 10, 2008 http://us.php.net/in_array in conjunction with a foreach loop may do the trick. Link to comment https://forums.phpfreaks.com/topic/95434-help-me-to-compare-two-string/#findComment-488566 Share on other sites More sharing options...
vcivilen Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks, but I just found other alternative method: Use: array_intersect http://us3.php.net/manual/en/function.array-intersect.php Again, Thank to charlieholder so much. Link to comment https://forums.phpfreaks.com/topic/95434-help-me-to-compare-two-string/#findComment-488574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.