Jump to content
Larry Ullman's Book Forums

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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...