Why can't I access this array?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Sat Oct 13, 2012 11:16 pm

As you have used names for your keys (i.e. 'not_found' => array....), you are replacing the numeric references to your array values and will only be able to access them using the string as the reference.

If you change it to:

Code: Select all

$_PAGE = array(
      'name' => 'not_found',
      'location' => 'page/notfound.php',
      'title' => 'Page Not Found'
      'name' => 'home',
      'location' => 'page/home.php',
      'title' => 'Home'
You can access using the numeric keys - try print_r($_PAGE) on the code above and your existing code and you will see the difference.

Post Reply