PHP: var_dump 输出未满
PHP: var_dump output is not full
有php个代码:
<?php
$lines = array();
$handle = @fopen("./1.csv", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$lines[] = $buffer;
foreach ($lines as $line) {
getNo($line);
}
}
fclose($handle);
}
function getNo($line) {
$allowedSources = array(
'_10' => 1,
'_20' => 1,
'_60' => 1
);
$providerList = explode(",",$line);
$sourceList = array();
foreach ($providerList as $providerInfo) {
$providerAndSource = explode("_",$providerInfo);
$provider = $providerAndSource[0];
$source = "_" . $providerAndSource[1];
if ( (array_key_exists($source,$allowedSources)) )
{
$sourceList[] = $source;
}
}
var_dump($sourceList);
}
?>
1.csv
1 4_10,5_20,6_60
输出为:
array(2) {
[0]=>
string(3) "_10"
[1]=>
string(3) "_20"
}
为什么“_60”不在输出中?
我刚刚添加
trim($line);
之后
foreach ($lines as $line) {
这解决了我的问题
有php个代码:
<?php
$lines = array();
$handle = @fopen("./1.csv", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$lines[] = $buffer;
foreach ($lines as $line) {
getNo($line);
}
}
fclose($handle);
}
function getNo($line) {
$allowedSources = array(
'_10' => 1,
'_20' => 1,
'_60' => 1
);
$providerList = explode(",",$line);
$sourceList = array();
foreach ($providerList as $providerInfo) {
$providerAndSource = explode("_",$providerInfo);
$provider = $providerAndSource[0];
$source = "_" . $providerAndSource[1];
if ( (array_key_exists($source,$allowedSources)) )
{
$sourceList[] = $source;
}
}
var_dump($sourceList);
}
?>
1.csv
1 4_10,5_20,6_60
输出为:
array(2) {
[0]=>
string(3) "_10"
[1]=>
string(3) "_20"
}
为什么“_60”不在输出中?
我刚刚添加
trim($line);
之后
foreach ($lines as $line) {
这解决了我的问题