Jump to content

The forums are in maintenance (read-only) mode until further notice. If you search these forums, you may find the answer you need. Otherwise, Google and Stack Overflow are reliable resources; arguably faster ones, too. I apologize for any inconvenience. (For those concerned--and thanks for being so thoughtful, there's no cause for alarm, but after 12+ years running these forums in my "spare time", I'm opting for a much deserved break to recharge my depleted batteries.)

- - - - -

Multidimensional Array

  • Please log in to reply
2 replies to this topic

#1 phpRob


    Advanced Member

  • Members
  • PipPipPip
  • 58 posts
  • LocationCardiff, South Wales

Posted 2 November 2011 - 7:12 AM


I'm working through Chapter 7 'Arrays'. Having read about multidimensional arays on w3schools they suggest writing them like so:

$books = array(
"PHP for the web" => array(1 => "Numbers", "Variables", "Arrays"),
"PHP and MySQL" => array(1 => "Databases", "Intro to SQL"),
"PHP Advanced" => array(1 => "Introduction to OOP", "Advanced OOP", "Frameworks")

Larry, do you still object to writing multidimensional arrays this way (nested)? What do you mean when you say it's too easy to make syntactical errors as the statement becomes more and more nested?

  • 0

#2 Josee


    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 2 November 2011 - 8:10 AM

I'm not Larry, but as a fellow PHP-learner I would say that it's much easier to forget a parenthesis or a comma with nested arrays. So, even if it would seem quicker to write it all in one statement, we may just as well waste time looking for a missing comma.
  • 0

#3 Larry



  • Administrators
  • 4,399 posts
  • LocationState College, PA (USA)

Posted 2 November 2011 - 10:25 AM

Thanks for the question. I don't categorically advise against writing multidimensional arrays in that way, just for beginners. Once you're quite adept at PHP programming, and are unlikely to make syntactical mistakes, it may make more sense to do things this way. But definitely not when you're first starting.
  • 0