无法将单独的数组索引/合并为单个数组

时间:2017-09-11 16:57:41

标签: php xampp

我有以下PHP代码:

<your scripting tool of choice here>

给我以下输出:

# Say I want the objects starting with "201", but have others:
$ gsutil ls gs://my-bucket/**
gs://my-bucket/other-thing
gs://my-bucket/2015/01/01/foo.jpg
gs://my-bucket/2016/12/25/christmas.jpg

$ export PATTERN="gs://my-bucket/201"
$ gsutil ls "$(python -c "print \"${PATTERN}\"[0:\"${PATTERN}\".rfind('/')]")" | grep -o "$PATTERN[^/]*"
gs://my-bucket/2015
gs://my-bucket/2016

但是我需要以下面的形式:

$file = new SplFileObject("fridge.csv");
$file->setFlags(SplFileObject::READ_CSV);
foreach ($file as $row) {
    list($item, $amount, $unit, $useby) = $row;
    if(date_create_from_format('d/m/Y',$useby) > $today) {
        #echo "Use Item $item by $useby </br>";

        print_r($row);

    }
}

如何将两个阵列合并为一个?

1 个答案:

答案 0 :(得分:1)

试试这个。

$list = array();
$file = new SplFileObject("fridge.csv");
$file->setFlags(SplFileObject::READ_CSV);
foreach ($file as $row) {
    list($item, $amount, $unit, $useby) = $row;
    if(date_create_from_format('d/m/Y',$useby) > $today) {
        $list[] = $row;
    }
}

print_r($list);