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 4096924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:06:29+00:00 2026-05-20T20:06:29+00:00

I found something similar to this question but it wasn’t related to strings. I’m

  • 0

I found something similar to this question but it wasn’t related to strings. I’m just looking for the best way to write the following code, I figured there has to be some short version I don’t know about.

<ul id="top-nav">
    <li <?php if($filename == "index.php"){echo ("class=\"current\"");} ?>><a href="index.php" title="Home">Home</a></li>
    <li <?php if($filename == "cause.php"){echo ("class=\"current\"");} ?>><a href="cause.php" title="Cause">Cause</a></li>
    <li><a href="order.php" title="Order">Order</a></li>
    <li class="drop-down<?php if($filename == "grand-prize-one.php" | $filename == "grand-prize-two.php"){echo (" current");} ?>"><a href="grand-prize-one.php" title="Grand Prizes">Grand Prizes</a>
      <ul>
        <li><a href="grand-prize-one.php" title="Grand Prize One">Grand Prize One</a></li>
        <li><a href="grand-prize-two.php" title="Grand Prize Two">Grand Prize Two</a></li>
      </ul>
    </li>
    <li <?php if($filename == "early-bird.php"){echo ("class=\"current\"");} ?>><a href="early-bird.php" title="Early Bird">Early Bird</a></li>
    <li class="drop-down<?php if($filename == "vehicles.php" || $filename == "vacations.php" || $filename == "other-prizes.php"){echo (" current");} ?>"><a href="vehicles.php" title="Electronics &amp; more">Other Prizes</a>
      <ul>
        <li><a href="vehicles.php" title="Vehicles">Vehicles</a></li>
        <li><a href="vacations.php" title="Vacations">Vacations</a></li>
        <li><a href="other-prizes.php" title="Electronics &amp; more">Electronics &amp; more</a></li>
      </ul>
    </li>
    <li <?php if($filename == "winners.php"){echo ("class=\"current\"");} ?>><a href="winners.php" title="Winners">Winners</a></li>
  </ul>

Is there a shorter way to write $filename == "vehicles.php" || $filename == "vacations.php" || $filename == "other-prizes.php"? I doubt I’d ever need it to accommodate more the 5-10 possible strings.

Thank you

SOLUTION

For those who find this question, I ended up doing this:

With my main PHP

<?php
 // My other code
 $grandPrizes = array("grand-prize-one.php","grand-prize-two.php");
 $otherPrizes = array("vehicles.php","vacations.php","other-prizes.php");
?>

My inline PHP in the li element

<?php if (in_array($filename, $grandPrizes)) {echo " current";} ?>
  • 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-20T20:06:30+00:00Added an answer on May 20, 2026 at 8:06 pm
    $filenames = array("vehicles.php","vacations.php","other-prizes.php");
    if (in_array($filename, $filenames)) {
        // code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked at various Q&As on SO similar to this question but haven't found
(I've searched for something similar, but haven't found anything that matches and/or works) I
I've done something similar to this with hbm files but so far I haven't
I just read this SE Post where it explains the question asked is similar
Okay this is similar to my last question but what I ended up doing
I found this question , which has an answer, but facebook changed the token
I already asked something similar, but the solution I found help me partially, so
This question sounds similar to many posed here, but it's obnoxiously different. I have
I found something like this in a SqlServer DB stored proc: SELECT stuff FROM
I have just found something very weird while developing a website. While trying to

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.