Jump to content

For loop and assoc. array not cooperating?


grippat

Recommended Posts

I wrote a simple function to validate a form. All it does right now is take an associative array and go through it making sure each element has a value. If it doesn't it adds to the error array which it returns. For some reason the $field_name inside the loop doesn't contain anything. But if I do a print_r($entry) it gives me this:

Array ( ['car'] => ['truck'] => ['bus'] => ['plane'] => )

And here's my function:

// Validate entry form.		function validateForm($entry) {						$err = array();						foreach($entry as $field_name) {				$field_name or $err[] = "Field $field_name is required.";			}						return $err;		}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...