php - Looping through an array for strings and putting the found strings into another array -
im trying loop through $files array and:
- find occurrences of "some-string".
- for every "some-string" occurrence found, need add array. (ie. $some_strings).
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
Post a Comment