我试图遍历$ files数组并且:
最后能够在for循环之外调用$ some_string数组进行操作(即count(),$ some_string [1])
foreach($files as $key=>$value)
{
if(strstr($value,'some-string')){
$some_strings = array();
$some_strings = $files[$key];
unset($files[$key]);
} elseif (strstr($value,'php')) {
unset($files[$key]);
}
}
在尝试计数($ some_strings)之前,每件事似乎都能正常工作。当我知道至少有10个值时,这只返回1个值。我做错了什么?
答案 0 :(得分:1)
试试这个
$some_strings = array();
foreach($files as $key=>$value)
{
if(strstr($value,'some-string')){
$some_strings[] = $files[$key];
unset($files[$key]);
} elseif (strstr($value, 'php')) {
unset($files[$key]);
}
}
//Now you can use $some_strings here without a problem
答案 1 :(得分:0)
试试这个
foreach($files as $key=>$value)
{
if(strstr($value,'some-string'))
{
$some_strings[$key] = $value;
unset($files[$key]);
} elseif (strstr($value,'php'))
{
$another_strings[$key] = $value;
unset($files[$key]);
}
}
echo count( $some_strings);
echo count( $another_strings);