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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:25:02+00:00 2026-05-12T11:25:02+00:00

Is there anyway I can clean up if($class == 2 AND $posts >=1){$showpost =1;}

  • 0

Is there anyway I can clean up

if($class == 2 AND $posts >=1){$showpost ="1";} else {$showpost ="$posts";
if($class == 3 AND $posts >=2){$showpost ="2";} else {$showpost ="$posts";
if($class == 4 AND $posts >=3){$showpost ="3";} else {$showpost ="$posts";
if($class == 5 AND $posts >=4){$showpost ="4";} else {$showpost ="$posts";
if($class == 6 AND $posts >=5){$showpost ="5";} else {$showpost ="$posts";
if($class == 7 AND $posts >=6){$showpost ="6";} else {$showpost ="$posts";
}}}}}}

As I don’t want }}}}}} at the end.

  • 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-12T11:25:02+00:00Added an answer on May 12, 2026 at 11:25 am
    if (($class >= 2) && ($class <= 7) && ($posts >= $class - 1))
        $showpost = $class - 1;
    else
        $showpost = $posts;
    

    The if is split into two sections:

     if (
         ($class >= 2) && ($class <= 7) // Check $class is between 2 and 7 inclusive
    
         && ($posts >= $class - 1)) // Check $posts >= $class -1
                                    // so if $class is 4 this checks if $posts >= 3
    

    This matches the logic in your original code – it’s just a matter of seeing the pattern.

    If you need $showpost to be a string (chances are you don’t), you can cast to string like this:

    $showpost = (string)$showpost;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen a couple examples out there that could possibly help me, but I
I wrote a Log class derived from System.Diagnostics.TraceListener like so public class Log :
This is what I'm planning to do. Suppose there are 2 machines A and
Wondering if there is any way to build and fire an event (e.g. on
I know, I know, I should use a modern shell... Anyway, so here is
Is the Visitor Pattern the fastest way to accomplish method parameter type identification (effectively
I have a few arrays and a resource that needs deletion, the value of
Update! See my dissection of a portion of the C# spec below; I think
I've finally tracked down an issue to bad code left in my ODX, presumably
I guess this question was asked in one way or another, but I'm looking

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.