PHP Taskbook Level 8.4
When a user enters a page, record the user's login time in the session. After refreshing the page, display the user's last login time on the screen.
Given some URL:
$url = 'http://test.com/dir1/dir2/dir3/page.html';
Get folders from it as an array:
['dir1', 'dir2', 'dir3']
Display the following pyramid on the screen:
1
22
333
4444
55555
666666
7777777
88888888
999999999
22
333
4444
55555
666666
7777777
88888888
999999999
Given a list of cities and their countries, stored in the following structure:
<?php
$data = [
[
'country' => 'country1',
'city' => 'city11',
],
[
'country' => 'country2',
'city' => 'city21',
],
[
'country' => 'country3',
'city' => 'city31',
],
[
'country' => 'country1',
'city' => 'city12',
],
[
'country' => 'country1',
'city' => 'city13',
],
[
'country' => 'country2',
'city' => 'city22',
],
[
'country' => 'country3',
'city' => 'city31',
],
];
?>
Write code that will remake the data structure into this:
[
'country1': [
'city11', 'city12', 'city13',
],
'country2': [
'city21', 'city22'
],
'country3': [
'city31', 'city32'
],
]