Why can't I access this array?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Re: Why can't I access this array?

Post by simplypixie » 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(
   array(
      'name' => 'not_found',
      'location' => 'page/notfound.php',
      'title' => 'Page Not Found'
   ),
   
   array(
      '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

Who is online

Users browsing this forum: No registered users and 1 guest