I have a function that creates a radio button in PHP:
// The function creates a radio button // function takes two arguments: value and name // function also creates buttons "sticky" function create_radio ($ value, $ name = 'gallon_price') {// start element: echo ' $ Value ";} // create_radio () function termination
Then I leave the PHP form to create an HTML form and call the function with the values three times which Three different gas prices represent.
& lt; span class = "input"> gt; php create_radio ('3.00'); create_radio ('3.50 '); Create_radio (' 4.00 ');? & Gt; & lt; / span & gt;
I am thinking that how can I change this code, so only one It would be possible to get output and only create_radio Function.
Thanks! <{$ Output = ""
; if (is_array ($ value)) {while (count ($ value)> 0) {$ Arr_value = array_pop ($ value); $ output. = Create_radio ($ arr_value);}} and {// start element: $ output. = '& Lt; input type = "radio" name = "' $ Name '"Value ="' $ Value ''; '; // Check for viscosity: If (isset ($ _ POST [$ name]) & amp; amp; $$ _POST [$ name] == $ value) {$ Output. = 'Checked = "Checked' ';} // Complete the element: $ output. =" / & Gt; $ Value ";} Return the output;}
A small function of the recursion will allow the function to work for arrays and non-array. Note: In order to call you to call html Echo will be required - do not call it.
No comments:
Post a Comment