note 107432 added to ref.strings

From: Date: Wed, 08 Feb 2012 21:58:02 +0000
Subject: note 107432 added to ref.strings
Groups: php.notes 
Request: Send a blank email to php-notes+get-185927@lists.php.net to get a copy of this message
Get the intersection of two strings using array_intersect <?php function string_intersect($string1, $string2) { $array1 = $array2 = array(); for($i = 0, $j = 0, $s1_len = strlen($string1), $s2_len = strlen($string2);($i < $s1_len) || ($j < $s2_len); $i++, $j++) { if($i < $s1_len) { $array1[] = $string1[$i]; } if($j < $s2_len) { $array2[] = $string2[$j]; } } return implode('', array_intersect($array1, $array2)); } ?> For more advanced comparison you can use array_uintersect as well. ---- Server IP: 69.147.83.197 Probable Submitter: 195.150.233.10 ---- Manual Page -- http://www.php.net/manual/en/ref.strings.php Edit -- https://master.php.net/note/edit/107432 Del: integrated -- https://master.php.net/note/delete/107432/integrated Del: useless -- https://master.php.net/note/delete/107432/useless Del: bad code -- https://master.php.net/note/delete/107432/bad+code Del: spam -- https://master.php.net/note/delete/107432/spam Del: non-english -- https://master.php.net/note/delete/107432/non-english Del: in docs -- https://master.php.net/note/delete/107432/in+docs Del: other reasons-- https://master.php.net/note/delete/107432 Reject -- https://master.php.net/note/reject/107432 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185927) next »