У меня есть следующий код PHP:
$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);
}
}
давая мне следующий вывод:
Array ( [0] => bread [1] => 10 [2] => slices [3] => 25/12/2017 )
Array ( [0] => cheese [1] => 10 [2] => slices [3] => 25/12/2017 )
Однако мне это нужно в следующей форме:
[0] => Array (
[0] => bread
[1] => 10
[2] => slices
[3] => 25/12/2017
)
[1] => Array (
[0] => cheese
[1] => 10
[2] => slices
[3] => 25/12/2017
)
Как я могу объединить два массива в один?
Попробуй это.
$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);
Других решений пока нет …