www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] printing out from complex array (Zend Cert)

  1. #1
    Join Date
    Apr 2006
    Posts
    245

    resolved [RESOLVED] printing out from complex array (Zend Cert)

    Hi all,

    I have came across the following question in a Zend Certification PHP mock exam tonight:

    Given the following array

    PHP Code:
    <?php
    $a 
    = array(
      
    => 'red',
      
    'green',
      
    'blue',
      
    'purple' => array(
        
    'house' => 'dog',
        
    'food' => 'meal',
        
    'here' => 'gone',
        
    'hello' => array(
          
    => 'goodbye',
          
    => 'something',
          
    'correct')));
    ?>
    Which of the following print statements will output the string "correct"?

    1. print $a['purple][4][3];
    2. print $a['purple']['hello'][9];
    3. print $a[2][4][3];
    4. print $a[2][4][9];
    5. print $a[4]['hello'][9];

    Many thanks,
    Picco

  2. #2
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    It would be print $a['purple']['hello'][9];
    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.

  3. #3
    Join Date
    Apr 2006
    Posts
    245
    Can I ask why it becomes $a['purple']['hello'][9]; ?

    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)?

    Merci ;-)

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    Correct, it will start from the next highest index regardless of any gaps.
    The first rule of Tautology Club is the first rule of Tautology Club.

  5. #5
    Join Date
    Apr 2006
    Posts
    245

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles