-2

I am trying to execute foreach loop but it doesn't show any value on HTML form. Here is code.

function displayOptions($options){
foreach($options as $option){
    printf("<option value='%s'>%s</option>",strtolower($option),ucwords($option));
}}

Here is a array..

$fruits=["mango","apple","orange","banana","coconut"];

Here is an HTML Code.

<select name="fruits" id="fruits">
   <option value="" disabled selected>Select Some Fruits</option>
     <?php displayOptions($fruits);?>
</select>

Can you help me?

Imran H
  • 11
  • 7

1 Answers1

0

There's an error in the function code. A typo actually.

Change ucword($option) to ucwords($option) and it would work.

Also, Make sure the function implementation or signature is before the its execution.