Trying to change statement so create_radio function is only called once (PHP) -


i have function creates radio button in php:

// function creates radio button. // function takes 2 arguments: value , name. // function makes button "sticky". function create_radio($value, $name = 'gallon_price')  {     // start element:     echo '<input type="radio" name="' .          $name .'" value="' . $value . '"';      // check stickiness:     if (isset($_post[$name]) && ($_post[$name] == $value))      {         echo ' checked="checked"';     }       // complete element:     echo " /> $value "; } // end of create_radio() function. 

i leave php form create html form , call function 3 times values represent 3 different gas prices.

<span class="input">         <?php             create_radio('3.00');             create_radio('3.50');             create_radio('4.00');         ?>     </span> 

i wondering how change code possible same output , make 1 call create_radio function.

thanks!

function create_radio($value, $name = 'gallon_price')  {     $output = "";     if (is_array($value)) {         while (count($value) > 0) {             $arr_value = array_pop($value);             $output .= create_radio($arr_value);         }     } else {         // start element:         $output .= '<input type="radio" name="' .          $name .'" value="' . $value . '"';          // check stickiness:         if (isset($_post[$name]) && ($_post[$name] == $value))          {            $output .= ' checked="checked"';         }        // complete element:         $output .= " /> $value ";     }     return $output; } 

a quick bit of recursion allow function work arrays , non arrays. note: in html need echo call create_radio not call it.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -