Jump to content

easy php question (I hope)


lupld

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;

    }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.