I have the following scenario:
- Array with multiple waypoints
- Want a new variable for every waypoint
- Number of waypoints is not fixed
The array stores the address data for the waypoint like street, number, zip, town etc.
I can loop and print the output of the array in foreach loop like:
foreach ($waypoints as $waypoint) {
echo $waypoint->street
echo $waypoint->nb
echo $waypoint->zip
echo $waypoint->town
}
What I'm trying to do is, to get a new variable for each waypoint. E.g:
$wp1 = Data from waypoint 1
$wp2 = Data from waypoint 2
What I have tried:
$waypointCount = count($waypoints);
for ($i = 1; $i < $waypointCount; $i++) {
$wp[$i] = $waypoints->street.' '.$waypoints->nb.' '.$waypoints->zip.' '.$waypoints->town.' '.$waypoints->state;
}
My idea was to count the number of waypoints, set a new variable for each waypoint number and store the corresponding waypointdata in the new variable. I'm kinda stuck on how to create the $wp[i] variables and assign the data to it. Does it need to be a combination with a for and a foreach loop?
Looking for some help to get me on the right direction. Thanks!
$waypoints[0]etc. What's the advantage of extracting that to individual variables?! (Hint: there is none.)