-2

I've tried looking through other places but I can't seem to find the answer. I know that a function can have more than one value being passed into it because the function itself accommodates for the two values. In this function right below, I can see that $required_fields will be passed into every occassion where "$field_length_array" occurs, but what does the $_POST do for me?

Many thanks from brother bear.

function check_max_field_lengths($field_length_array) {
$field_errors = array();
foreach($field_length_array as $fieldname => $maxlength ) {
    if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $field_errors[] = $fieldname; }
}
return $field_errors;
}


function check_max_field_lengths($field_length_array) {
$field_errors = array();
foreach($field_length_array as $fieldname => $maxlength ) {
    if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $field_errors[] = $fieldname; }
}
return $field_errors;
}



$required_fields = array('username', 'password');
$errors= array_merge($errors, check_required_fields($required_fields, $_POST));

$fields_with_lengths = array('username' => 30, 'password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
moto
  • 194
  • 3
  • 13
  • how is this not a real question? Adidi helped me to realize that the second argument can be used in certain situations, but as the codes are written here, it does nothing for me. This is something that I wanted to double check as I was confused.. – moto Apr 19 '13 at 22:27

1 Answers1

1

In this case the $_POST does nothing because there is no use to it inside the function as a second argument. You can send more then one argument but then inside the function you should see a use of it like func_get_args() - The function does make use of $_POST - but not as a function argument but as the global object of the php web scope.

Adidi
  • 5,097
  • 4
  • 23
  • 30
  • so if I were to be using func_get_args() then it might be helpful that I have the $_POST there, but I'm guessing that there's no point of having the $_POST there for now? (I'm at the end of a lynda php and mysql essentials tutorial, and for the first time this guy started passing more arguments into the calling of his function than the defining of his function had) – moto Apr 19 '13 at 18:27
  • well - again - it can be done - in your example - it does not have any use - you can remove the second argument from the function or use func_get_args()[1] instead of the $_POST inside the function - but this is be rather stupid :) - its just so you understand - this is how dynamic php function works (when you can send 1 or more parameters to the function)... – Adidi Apr 19 '13 at 18:29