3v4l.org

run code in 500+ PHP versions simultaneously
<?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;
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.25, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
<pre>array(5) { [1]=> array(3) { [0]=> string(12) "http://a.com" [1]=> string(12) "http://b.com" [2]=> string(12) "http://c.com" } [2]=> array(2) { [0]=> string(12) "http://d.com" [1]=> string(12) "http://e.com" } [3]=> array(1) { [0]=> string(12) "http://f.com" } [4]=> array(1) { [0]=> string(12) "http://g.com" } [5]=> array(1) { [0]=> string(12) "http://h.com" } } <tr> <td>1</td> <td>http://a.com| http://b.com| http://c.com</td> </tr> <tr> <td>2</td> <td>http://d.com| http://e.com</td> </tr> <tr> <td>3</td> <td>http://f.com</td> </tr> <tr> <td>4</td> <td>http://g.com</td> </tr> <tr> <td>5</td> <td>http://h.com</td> </tr>

preferences:
91.5 ms | 1864 KiB | 4 Q