Jump to content
Larry Ullman's Book Forums

Function Arguments From Chapter 3, Page 103

Recommended Posts

Hi All,


I am struggling with the naming of values and a comparison operator. I was fine with how this all worked until I ran into this snippet of code. I am not sure how it works or the logic behind it.



function create_radio($value, $name = 'gallon_price') {


// Start the element:

echo '<input type="radio" name="' . $name .'" value="' . $value . '"';


// Check for stickiness:

if (isset($_POST[$name]) && ($_POST[$name] == $value)) {

echo ' checked="checked"';



// Complete the element:

echo " /> $value ";


Specifically, the comparison value of ($_POST[$name] == $value) doesn't make since to me. We defined the variable $name as 'gallon_price' and $value as some input which would normally be our supplied gasoline price (a number) I understand this is not really here to comare actual values but to see if they are set, but I don't see how this does this. It seems more logical to see that $value is set. Can someone explain how this works?


Signed - Confused a bit.



Link to comment
Share on other sites

Keep in mind that $name is just a string value that defaults to 'gallon_price' when no explicit value is provided for the $name parameter when the function is called.

With that said, $_POST[$name] really just essentially means $_POST['gallon_price'], which refers to the value input for the 'gallon_price' input field in the submitted form.


Does that make sense?

Also, please do not post the same question three times in a row.

Thank you.

  • Upvote 1
Link to comment
Share on other sites


  • Create New...