How can I turn the code below into a single array when its in the while loop? An example would help.
Here is my PHP code.
while($row = mysqli_fetch_array($dbc)){
$category = $row['category'];
$url = $row['url'];
}
How can I turn the code below into a single array when its in the while loop? An example would help.
Here is my PHP code.
while($row = mysqli_fetch_array($dbc)){
$category = $row['category'];
$url = $row['url'];
}
Building off mawg's solution and your new requirement:
$data = array();
while ($row = mysqli_fetch_array($dbc)) {
$data[$row['category']] = $row['url'];
}
This would create an associative array with the category name as the key.
Or you could do:
$data = array();
while ($row = mysqli_fetch_array($dbc)) {
$data[] = array(
'row' => $row['url'],
'category' => $row['category'],
);
}
Which would create an array of associative arrays that would contain the URL and category for each row.