Each device can have 2 power supplies, but only 1 is present (the array)… how do I alter the foreach loop so I can target the one in the array?
I tried
The apparent answer, in the form of a question (Jeopardy theme can be heard playing), why are you using a foreach(){} loop at all? What result are you trying to produce if there’s only one PS and what result are you trying to produce if there’s two?
Edit: Let me add another question. You are looping for x = 1, to 2. Does that specifically matter? Would 0 to 1 work?
You see how you can have 2 power trails (blue) but I only have 1 currently.
I want to only list the one (by having the image of a power strip) and still be able to add a power strip below
the top trail has a power strip, while the other doesnt…
yep, i have to be prepared if there are 4 power trails
While you didn’t actually answer the question, maybe this is the solution -
// loop over the number of 'elements' to display
foreach(range(1,$row['total_plugs']) as $x)
{
// test if there's data for the current $x value
if(isset($power_supplies[$x-1]))
{
// do whatever you want with the sub-array of data in $power_supplies[$x-1]
}
}
The theme there is you are looping to produce some number of display elements. As you are doing that, you test if there’s data corresponding to each element.