php - Finding a part of string in an array of strings -


iv been looking way search through array of strings , find if there strings contain part of string, if there merge whole array onto array. eg:

searching jav: array->[java] -> return value , add whole array 

after looking around on stackoverflow , testing found solution using strpos works...kind of:

$matches=array(); //just here show array declared , filled items prior calling   foreach($myarray $fn){     if(strpos($fn,$searchstring)){         $matches = array_merge($myarray,$matches);     }     } 

the issue is, instead of adding whole array adding search string each loop however, after double checking number of times dont understand why. tts adding original search item rather entire other array.... eg.

if search jav shown above array merge create array of correct length value :

javjavjavjavjav 

any in understanding why or how correct appreciated.

the function strpos return false or 0, array matches not save word text jav.

this solution:

$myarray = ['java', 'java3', 'mouse', 'java2', 'keyboard']; $matches = []; foreach ($myarray $fn) {     if (strpos($fn, 'jav') !== false) {         $matches[] = $fn;     } } 

ps: don't know if understood correctly question, hope.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -