Jump to content

Turning an array into a select field


funkafaction

Recommended Posts

It is taking the array that you had loaded with data, and then foreach , $k which refers to the key which would be GMT -12:00 set its value to $v which would be "International Date Line West". Then go through till the end of the array. Printf is the same as echo but allows formatting. so the %s refers to a string. And then what ever order you put the variables in is the places they will be placed and then echoed. So $k (which is the key) is set to the value, and the value of key ($v)  is set to be showed.

 

full code would be

<?
$timezone_array = array(
               "GMT -12:00" => "International Date Line West"
            );

foreach ($timezone_array as $k=>$v) {
       printf('<option value="%s">%s</option>', $k, $v);
}
?>

 

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.