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

  • Home
  • SEARCH
  • 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 8761161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:13:17+00:00 2026-06-13T15:13:17+00:00

How can I simplify this with less code? <?php $items[‘link1’] = ‘Link 1’; $items[‘link2’]

  • 0

How can I simplify this with less code?

<?php
$items['link1'] = 'Link 1';
$items['link2'] = 'LInk 2';
$items['link3'] = 'Link 3';
?>

<?php foreach ($items as $url => $text): ?>
<?php $class = false; if (isset($active) and $active == $url) $class = array('class' => 'current'); ?>
<?php echo '<li>' . Html::anchor($url, $text, $class) . '</li>' ?>
<?php endforeach; ?>

And also, for some reason the “current” class is not showing when on the particular URL.

Thanks

  • 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-06-13T15:13:18+00:00Added an answer on June 13, 2026 at 3:13 pm

    This is less code:

    <?php
    
    $items=array(
      'link1' => 'Link 1',
      'link2' => 'LInk 2',
      'link3' => 'Link 3',
    );
    
    foreach ($items as $url => $text) {
      $class = false;
      if (isset($active) && $active == $url)
        $class = array('class' => 'current');
      echo '<li>' . Html::anchor($url, $text, $class) . '</li>';
    }
    
    ?>
    

    But since I don’t know what it’s supposed to do, I can’t really help beyond pretty-printing it for you. More details, please.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if I can simplify and use less lines of code for this
How can I simplify this code? if needed I can rename the .php files
Can anyone help me figure out how I could simplify this code, without using
Okay, I believe that I can simplify this line of code except I can't
Can you simplify this code?. Is there anything we can do to make it
how can i simplify this code? The Mouse-Events are all quite similar. Therefore there
Is there a way that I can simplify this code: var topic_html = obj.$form.find(#select-topic).html();
Hi I'm trying to simplify this code but can't think which way to do
How can I simplify this PHP condition? <?php function authUser( $user, $pass ) {
My question is similar to this one , but I can simplify it some.

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.