Jump to content
Larry Ullman's Book Forums

Multidimensional Array


Recommended Posts

Hi,

 

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?

 

Thanks

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 Share

×
×
  • Create New...