Jump to content

Recommended Posts

Is it possible to make a loop inside of an array?

IE:

[code]
array(for($x=1;$x<31;$x++) {echo "Shelf $x";});
[/code]

I have tried this already in my code, and I get:
Parse error: parse error, unexpected T_FOR, expecting ')' in C:\Server\wamp\www\update.php on line 68

So I think either its A) Not possible, or B) coding it wrong.
Link to comment
https://forums.phpfreaks.com/topic/35713-looping-in-an-array/
Share on other sites

Cool that got rid of the error.  Now Im just trying to get them all into a combo box.  Code runs fine, the combo box pops up, but the array data isnt in it.

[code]
$loc=$row['PC_LOC'];
<tr><td>Location</td><td><select name='status'>
<?php
    $location = $array = array();
for($x=1; $x<31; $x++)
    {$array[]="Shelf ".$x;}

foreach($location as $locat)
{
  if($locat == $loc)
{ echo "<option selected>".$locat."</option>"; }
else
{ echo "<option>".$locat."</option>"; }
}
?> </select></td></tr>
[/code]

Link to comment
https://forums.phpfreaks.com/topic/35713-looping-in-an-array/#findComment-169224
Share on other sites

I believe you want the shelf number in the combo box correct?

you would do this as followed:

[CODE]
$loc=$row['PC_LOC'];
<tr><td>Location</td><td><select name='status'>
<?php
    $location = array();
for($x=1; $x<31; $x++)
    {$location[]="Shelf ".$x;}

foreach($location as $locat)
{
  if($locat == $loc)
{ echo "<option selected>".$locat."</option>"; }
else
{ echo "<option>".$locat."</option>"; }
}
?>
[/CODE]
Link to comment
https://forums.phpfreaks.com/topic/35713-looping-in-an-array/#findComment-169233
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.