我有一个数组$all_orders
,其中包含数组,$ temp_array包含爆炸后由8
个单词组成的字符串的每次迭代,$handle
由3 lines
组成文件:
while(!feof($handle))
{
$order=fgets($handle);
$temp_array=explode(",",$order);
array_push($all_orders,$temp_array);
}
现在,当我尝试计算$all_orders
数组元素(应该是3)时,我只得到8:
echo count($all_orders);// display 8
为什么我没有得到3?
修改
这是我在尝试打印到数组内容时得到的结果:
Array
(
[0] => Array
(
[0] =>
)
[1] => Array
(
[0] =>
)
[2] => Array
(
[0] => 1
[1] => 1
[2] => chaine.com
[3] => chaine
[4] => chaine
[5] => chaine
[6] => chaine
[7] => chaine
)
[3] => Array
(
[0] =>
)
[4] => Array
(
[0] => 2
[1] => 1
[2] => chaine@fudd.com
[3] => chaine.
[4] => chaine
[5] => chaine
[6] => chaine
[7] => chaine
)
[5] => Array
(
[0] =>
)
[6] => Array
(
[0] => 3
[1] => 2
[2] => chaine@bunny.com
[3] => chaine.
[4] => chaine
[5] => chaine
[6] => chaine
[7] => chaine
)
[7] => Array
(
[0] =>
)
)
答案 0 :(得分:1)
你有两个问题之一:
\r\n
平台上使用\n
)无论问题究竟是什么,都应该解决它:
while(!feof($handle)) {
// Evaluating the trimmed line as a bool will effectively skip blank lines
if (!trim($order = fgets($handle))) continue;
$all_orders[] = explode(',', $order);
}