3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 7 => 'a1455656400,96.64,96.85,94.61,95.02,47490678', 8 => '1,98.12,98.21,96.15,96.67,44390173' ]; $date = new \DateTime('now'); $date->format('U = Y-m-d H:i:s'); $quotations = []; for ($i = 7; $i < 9; $i++) { $matches = []; if (preg_match('/^a?(\d+),(\d+\.\d+),(\d+\.\d+),(\d+\.\d+),(\d+\.\d+),(\d+)$/', $array[$i], $matches)) { if (preg_match('/^a(\d+)/', $array[$i])) { $timestamp = $matches[1]; $date->setTimestamp($timestamp); } else { $date->modify("+{$matches[1]} day"); $timestamp = "NULL"; } $quotations[] = [ 'date' => $date, 't' => $timestamp ]; } } var_dump($quotations);

preferences:
26.48 ms | 402 KiB | 5 Q