Welcome to WebmasterWorld Guest from 23.22.200.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# Explanation of Array Functionality

#### w9914420

4:14 pm on May 9, 2013 (gmt 0)

#### New User

joined:Mar 21, 2005
posts: 22

Hello All,

Before I start I am a complete newbie to PHP and I am trying to further my education. I have been looking into arrays and Have come across this particular line of code.

``\$font_table = array(array(array('nothing', 'one'),       array('two', 'three')),     array(array('four', 'five'),       array('six', 'seven')));echo \$font_table[!empty(\$a['Font3'])][!empty(\$a['Font2'])][!empty(\$a['Font'])];``

From my understanding of arrays this seems to be a multidimensional but what I'm interesting in is the echo response which pinpoints the keys values. you can pin point different keys based upon weather or not a key is empty. I have been scratching my head and tried to look into why this works. I just need a bit of help, or at least an explanation to what is going on. I would be very great full if someone could be kind enough to give me insight into this piece of code.

regards

w9914420

#### lucy24

7:52 pm on May 9, 2013 (gmt 0)

#### Senior Member from US

joined:Apr 9, 2011
posts:12999

this seems to be a multidimensional

Yes, it unpacks to (thank you, text editor)
``\$font_table[0][0][0] = 'nothing'\$font_table[0][0][1] = 'one'\$font_table[0][1][0] = 'two'\$font_table[0][1][1] = 'three'\$font_table[1][0][0] = 'four'\$font_table[1][0][1] = 'five'\$font_table[1][1][0] = 'six'\$font_table[1][1][1] = 'seven'``

working outward from
``array('two', 'three'){is the same as}\$blahblah[0] = 'two'\$blahblah[1] = 'three'``

The short form obviously saves a lot of space-- but also creates a lot more room for confusion and error.

#### w9914420

9:26 pm on May 9, 2013 (gmt 0)

#### New User

joined:Mar 21, 2005
posts: 22

lucy24 thank you for making me see the light, all is clear.

regards

w9914420

10:00 pm on May 10, 2013 (gmt 0)

#### Senior Member

joined:Dec 13, 2009
posts:945

When using the short form, you can spare yourself / your peers a few headaches just by spacing it out a bit.

``\$font_table = array(  array(    array(      'nothing',      'one'    ),    array(      'two',      'three'    )  ),  array(    array(      'four',      'five'    ),    array(      'six',      'seven'    )  ));``

#### w9914420

2:31 pm on May 11, 2013 (gmt 0)

#### New User

joined:Mar 21, 2005
posts: 22