Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:47:53+00:00 2026-05-20T10:47:53+00:00

This is what i am currently using <?php $sidebar = $this->data[‘sidebar’]; $lastKey = array_pop(array_keys($sidebar));

  • 0

This is what i am currently using

<?php $sidebar = $this->data['sidebar']; 
$lastKey = array_pop(array_keys($sidebar));
$sidebar = $this->data['sidebar'][$lastKey]; ?>
<?php foreach($sidebar as $key => $item) { ?>
<li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
    if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"><?php echo htmlspecialchars($item['text']) ?></a></li>
<?php } ?>

This is what i get (http://pastebin.com/t6Y2ZtMF) when i print_r($sidebar);
I want to get the last Array which is Categories and turn it into links.

I am new to php, so my method could be wrong even though it works. I is there a right way to pull the Categories Array or the above code is good as it is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:47:53+00:00Added an answer on May 20, 2026 at 10:47 am
    $lastValue = end($array);
    $lastKey = key($array); // current key, which is the last since you called end()
    

    After update:

    You don’t seem to be needing the key, only the array:

    <?php $lastSidebarValue = end($this->data['sidebar']); ?>
    <?php foreach ($lastSidebarValue as $key => $item) : ?>
        business as usual...
    <?php endforeach; ?>
    

    Since you know you want the key 'Categories' though (not the last key), this seems the most logical thing to do:

    <?php foreach ($this->data['sidebar']['Categories'] as $key => $item) : ?>
        business as usual...
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using this script to get new data every second from record_count.php
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
I am currently using this code to grab key-strokes, but I am missing e.g.
I am currently using this code to get data from a URL: NSURL *url
I have a problem with RewriteRules. I'm currently using this rule: RewriteRule ^([^/.]+)/?$ index.php?clip=$1
I am using PHP to echo my list of navigation options, this is being
I'm currently using php's imagick to convert some PDF to images - This works
I am currently using PHP to paginate my data from mysql. I want to
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm currently using this jQuery validate plugin and having an issue in IE where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.