Jump to content

For Each Statements


Xtremer360

Recommended Posts

Anything wrong with this because I got a parse error ONLY after adding to create this.

 

<?php
                            $visible = array('Yes', 'No');
                            foreach($visible as $visible):
                            $visible2 = array('yes', 'no');
                            foreach($visible2 as $visible2):
                        ?>      

Link to comment
https://forums.phpfreaks.com/topic/214854-for-each-statements/
Share on other sites

Here's the whole select tag. The idea is to have the value of the options be yes and no but for it to show Yes and No to the user to select either.

 

<select name="visible" class="dropdown">
                        <option value="0">- Select -</option>
                        <?php
                            $visible = array('Yes', 'No');
                            foreach($visible as $visible):
                            $visible2 = array('yes', 'no');
                            foreach($visible2 as $visible2):
                        ?>        
                            <option value="<?php echo $visible2; ?>"<?php if($visible == $row['visible']): echo ' SELECTED'; endif; ?>><?php echo $visible; ?></option>
                         
                         <?php endforeach; ?>
                        </select>

Link to comment
https://forums.phpfreaks.com/topic/214854-for-each-statements/#findComment-1117706
Share on other sites

$options = array(
    // option_val => display_text
    "yes" => "Yes",
    "no" => "No"
);
foreach($options as $key => $val) {
    echo "<option value=\"".$key."\"";
    if($key == $row['visible']) echo " selected=\"selected\"";
    echo ">".$val."</option>\n";
}

Link to comment
https://forums.phpfreaks.com/topic/214854-for-each-statements/#findComment-1117712
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.