Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Help, foreach
#2
The problem is you're attempting to use the foreach construct upon a string. Even though you assigned the $errors variable to an empty array (and therefore type-casting it to an array), PHP's loose typing enables us to type-juggle our variables. This is exactly what you're doing by assigning the $errors variable to a string. You'll need to change how you're assigning the errors if you'd like to fix your problem:
PHP Code:
$errors[] = 'error here';
$errors[] = 'error2 here'

Because we've used the square brackets upon the $errors variable, we're now inserting a new element into our array, rather than type-juggling it to a string with only one value.
Reply


Messages In This Thread
PHP Help, foreach - by Tubby - 12-09-2012, 02:59 PM
RE: PHP Help, foreach - by Haxalot - 03-18-2013, 12:52 PM
RE: PHP Help, foreach - by Excuse - 07-02-2013, 09:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 789 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,313 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 1 Guest(s)