Jump to content

Bert1455

New Members
  • Posts

    6
  • Joined

  • Last visited

Bert1455's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks guys, I really appreciate it and this website is extremely helpful.
  2. I'm sorry if I didn't make it clear and that's also what I thought initially, it's in the PHP Solution 2nd Editions ( I know quite few people who have it), but the book states clearly that it's user text input.
  3. The context is that value would be user input in a form. I'm confused about the is_array portion in the 4th line. The user input shown in the book states would be something like an e-mail, name, or comment. I'm confused as to why is_array would be used. I mean when will user input every be an array? Wouldn't that make the condition always true? Anyways, thanks for the reply, I finally understood that last portion at the bottom, which I thought was assigning $key to the $temp variable defined above.
  4. Thank you Cadaver. My only question now is how this would apply to a form in which users type in say their e-mail address or leaving comments?
  5. Wait so $value is a form field? I really don't understand this portion of his code. I thought $value was user input. And I was thinking why user input would ever be an array? I thought $key would be the form fields. I'm sorry I'm a beginner and this made me quit confused.
  6. I've been trying to learn PHP with the PHP Solutions book second editions by David Powers. I seemingly can't find anyway of contacting him about the code I found in the book. <?php foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { $missing[] = $key; } elseif (in_array($key, $expected)) { // otherwise, assign to a variable of the same name as $key ${$key} = $temp; } } I understand that is_array checks whether or not $value is an array but I can't find a scenario in which it would be array and therefore why it would be there at all. Also I the last part relies on the fact above which I don't understand as well.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.