$request = $pdo->prepare("SELECT `id`, `name` FROM `fruits` ORDER BY `name`");
$request->execute();
$data = [];
$prevLetter = '';
$subArray = [];
foreach ($row = $request->fetch(PDO::FETCH_ASSOC)) {
$firstLetter = mb_substr($row['name'], 0, 1);
if ($prevLetter != $firstLetter) {
if (count($subArray) > 0)
$data[] = $subArray;
$subArray = [];
$prevLetter = $firstLetter;
}
$subArray[] = $row;
}
if (count($subArray) > 0)
$data[] = $subArray;
[callback]
exten => _X.,1,Answer()
same => n,Playback(всё, что хотите сказать менеджеру)
same => n,Dial(канал/${EXTEN})
$array1 = array(50888 => array('ELEMENTS' => array('1028', '1030')),
50889 => array('ELEMENTS' => array('1048')),
50890 => array('ELEMENTS' => array('1039')),
);
$array2 = array('1028', '1039');
$array3 = array_reduce(array_keys($array1), function($carry, $key) use ($array1, $array2) {
if (count(array_intersect($array1[$key]['ELEMENTS'], $array2)) > 0)
$carry[] = $key;
return $carry;
}, array());
SELECT `t1`.`code`, `t1`.`name`, `t1`.`max_int1`, `t2`.`name`, `t2`.`max_int2`
FROM (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int1` AS `max_int1`
FROM (
SELECT `code`, MAX(`int1`) AS `int1`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int1` = `m`.`int1`
) AS `t1`
JOIN (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int2` AS `max_int2`
FROM (
SELECT `code`, MAX(`int2`) AS `int2`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int2` = `m`.`int2`
) AS `t2` ON `t1`.`code` = `t2`.`code`
if (preg_match_all('/(\d\d)(\S{3})\s+\S+\s+\d+\s+(\S{3})-.*?(\d\d)(\d\d)\s+(\S{3})-.*?ARRIVAL:(\d\d)(\d\d)(?: (\d\d)(\S{3}))?/s',
$data, $matches, PREG_SET_ORDER)) {
foreach($matches as $flight) {
if (!isset($flight[9])) {
$flight[9] = $flight[1];
$flight[10] = $flight[2];
}
list($full, $depDay, $depMonth, $depIATA, $depHour, $depMin,
$arrIATA, $arrHour, $arrMin, $arrDay, $arrMonth) = $flight;
print "$depDay $depMonth $depHour:$depMin $depIATA => $arrDay $arrMonth $arrHour:$arrMin $arrIATA\n";
}
}