Jump to content

Recommended Posts

I'd look this up if I knew what to search for.. but here's what I need... I want to set a variable to something different based on which number it is, so I need to have an if statement try if the number is 1-99...

<?php
    if($rnum = "1-9") {
    $varrnum = "1000"."$rnum";
    }
    if($rnum = "10-99") {
    $varrnum = "100"."$rnum";
    }
    if($rnum = "100-999") {
    $varrnum = "10"."$rnum";
    }
    if($rnum = "1000-9999") {
    $varrnum = "1"."$rnum";
    }else{
    $varnum = $rnum;
    }
    $lup = $varrnum
?>

*edit* I know the way this is set up it will look for $rnum to be exactly 10-99.. which is why I am asking how to do this...*/edit*

Link to comment
https://forums.phpfreaks.com/topic/64027-easy-php-question-i-hope/
Share on other sites

    if($rnum >= 1 && $rnum <= 9 ) {

    $varrnum = "1000"."$rnum";

    }

    else if($rnum >= 10 && $rnum <= 99 ) {

    $varrnum = "100"."$rnum";

    }

    else if($rnum >= 100 && $rnum <= 999 ) {

    $varrnum = "10"."$rnum";

    }

    else if($rnum >= 1000 && $rnum <= 9999 ) {

    $varrnum = "1"."$rnum";

    }else{

    $varrnum = $rnum;

    }

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.