<?php
$fake_db_results = [
['session_id' => 1, 'page_url' => 'http://a.com'],
['session_id' => 1, 'page_url' => 'http://b.com'],
['session_id' => 1, 'page_url' => 'http://c.com'],
['session_id' => 2, 'page_url' => 'http://d.com'],
['session_id' => 2, 'page_url' => 'http://e.com'],
['session_id' => 3, 'page_url' => 'http://f.com'],
['session_id' => 4, 'page_url' => 'http://g.com'],
['session_id' => 5, 'page_url' => 'http://h.com']
];
$paths = [];
foreach ($fake_db_results as $row) {
if ( ! array_key_exists($row['session_id'], $paths) || ! is_array($paths[$row['session_id']])) {
$paths[$row['session_id']] = [];
}
array_push($paths[$row['session_id']], $row['page_url']);
}
echo '<pre>';
var_dump($paths);
$html = '';
foreach ($paths as $session => $page) {
$html .= "<tr>\n";
$html .= '<td>' . $session . "</td>\n";
$html .= '<td>' . implode('| ', $page) . "</td>\n";
$html .= "</tr>\n";
}
echo $html;
preferences:
132.12 ms | 406 KiB | 5 Q