Jump to content

Echo Multi Dimensional Array Out


sungpeng

Recommended Posts

Arrays in PHP are 0-indexed, which means that in order to get the first value you have to reference index 0. Like this:

echo $days[2][0];

 

PS: Adding quotes around the variable like that is completely useless, as they should only be used if you're defining actual string content. The variable already contains strings, and even if it didn't PHP will automatically cast it to a string when using echo.

The first line is also not necessary, as you're overwriting it in the second. array () returns a new array object, so no matter what the variable contained earlier it'll be overwritten with the new array.

0-indexed means that 0 is the first number used in a count, while 1-indexed means that 1 is the first number used. Nothing (at least that I know) uses 2-indexed counting.

In normal life we're used to 1-based indexing, as we start to count everything at 1. PHP, however, starts to count at 0. So if you have 3 elements in an array, you'll find them at indices 0, 1, and 2.

 

A Google search should bring up lots more information on this subject, if you still have problems with understanding it.

check with you why need to put {} in front and at the end of echo array ?

 

Required for PHP to parse complex expressions within a string - see the section on "Complex Expressions" on this page of the manual

http://www.php.net/manual/en/language.types.string.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.