php - Looping through an array for strings and putting the found strings into another array -


im trying loop through $files array and:

  1. find occurrences of "some-string".
  2. for every "some-string" occurrence found, need add array. (ie. $some_strings).
  3. finally able call $some_string array outside of loop manipulation(ie. count(), $some_string[1])

    foreach($files $key=>$value) { if(strstr($value,'some-string')){     $some_strings = array();     $some_strings = $files[$key];     unset($files[$key]); } elseif (strstr($value,'php')) {     unset($files[$key]);   }   } 

every things seems work fine until try count($some_strings). returns 1 value when know there atleast 10 values. doing wrong?

try this

$some_strings = array(); foreach($files $key=>$value) {     if(strstr($value,'some-string')){        $some_strings[] = $files[$key];        unset($files[$key]);     } elseif (strstr($value, 'php')) {       unset($files[$key]);     } } //now can use $some_strings here without problem 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -