homepage Welcome to WebmasterWorld Guest from 54.204.141.129
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Explanation of Array Functionality
w9914420




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

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




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

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




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

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

regards

w9914420

Readie




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

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




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

Hi Readie,
I absolutely agree, now that I understand arrays better.

thanks

w9914420

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved