i am playing with an array in PHP (still learning arrays!)
i have the following PHP code to pull data from my eventsTest table, and echo the array;
<?php
if ($result = $con->query("SELECT * FROM eventsTest")) {
$array = array();
while($row=mysqli_fetch_assoc($result)) {
$array[] = $row;
}
print "<pre>";
print_r($array);
print "</pre>"; // DEBUG--- show all array data
}
which prints my array as:
Array
(
[0] => Array
(
[id] => 1
[dateStart] => 2018-12-26
[dateEnd] => 2018-12-26
[name] => Test Event 1
)
[1] => Array
(
[id] => 2
[dateStart] => 2018-12-27
[dateEnd] => 2018-12-27
[name] => Test Event 2
)
)
instead of the [0] [1] [2] keys as the index, can i set the dateStart as the key for the array index?
for example:
Array
(
[2018-12-26] => Array
(
[0] => Array
(
[dateEnd] => 2018-12-27
[name] => Test Event 1
)
)
[2018-12-27] => Array
(
[0] => Array
(
[dateEnd] => 2018-12-27
[name] => Test Event 2
)
)
[2018-12-28] => Array
(
[0] => Array
(
[dateEnd] => 2108-12-28
[name] => Test Event 3
)
[1] => Array
(
[dateEnd] => 2018-12-28
[name] => Test Event 4
)
)
)
grouping the dateStart also in the same index if there is multiple rows with the same dateStart for example?