Jump to content

array is function


andyd34

Recommended Posts

 

I have a fuction that uses an array to populate and select list

$fruit = array(
                            '1'  =>  'apple',
            '2'	  =>  'pear',
            '3'	  =>  'orange',
            '4'	  =>  'banana',
            '5'	  =>  'clementine',
            '6'	  =>  'kiwi',
      );

 

 

I then have the following

 

             for($i=1 ; $ <= 6 ; $i++)
                  {
                     $value = "<option value='$fruit[$i]>$fruit[$i]</option>";
                  }

 

What I want though is the value of the option to be the index of the array, does anyone have any ideas

Link to comment
https://forums.phpfreaks.com/topic/190663-array-is-function/
Share on other sites

             for($i=1 ; $ <= 6 ; $i++)
                  {
                     $value = "<option value='$fruit[$i]>$fruit[$i]</option>";
                  }

 

What I want though is the value of the option to be the index of the array, does anyone have any ideas

 

So you want the value to be the increment number? as in array[1]  = "apple" you want "1" to be the value?

 

if so...

 

             for($i=1 ; $ <= 6 ; $i++)
                  {
                     $value = "<option value='".$i."'>".$fruit[$i]."</option>";
                  }

Link to comment
https://forums.phpfreaks.com/topic/190663-array-is-function/#findComment-1005504
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.