[RESOLVED] printing out from complex array (Zend Cert)
I have came across the following question in a Zend Certification PHP mock exam tonight:
Given the following array
Which of the following print statements will output the string "correct"?
$a = array(
1 => 'red',
'purple' => array(
'house' => 'dog',
'food' => 'meal',
'here' => 'gone',
'hello' => array(
5 => 'goodbye',
8 => 'something',
1. print $a['purple];
2. print $a['purple']['hello'];
3. print $a;
4. print $a;
5. print $a['hello'];
It would be print $a['purple']['hello'];
You can not use index 2, since $a does not have an index 2, so why would that even be an option? The same goes for the "purple" index. That array does not have an index 4.
Can I ask why it becomes $a['purple']['hello']; ?
Is it safe to assume that it takes the next highest index from the last created (8) and doesn't take it from the lowest available (0)?
Correct, it will start from the next highest index regardless of any gaps.
Brilliant - thanks again!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread