代码不显示PHP

时间:2015-09-22 11:19:33

标签: php

所以我写出了我的所有代码,它一直都是应该的,但由于某些原因,它似乎并不想在屏幕上输出任何东西,就像它应该......

有人可以帮帮我吗? 感谢

代码:

$points_disp = $user_data['points'];
$oneFDigit = substr($points_disp, 0, 1);
$oneSDigit = substr($points_disp, 1, 1);
$oneRange = range(1000, 9999);

$tenFDigit = substr($points_disp, 0, 2);
$tenSDigit = substr($points_disp, 2, 1);
$tenRange = range(9999, 99999);

$hunFDigit = substr($points_disp, 0, 3);
$hunSDigit = substr($points_disp, 3, 1);
$hunRange = range(99999, 999999);

$oneMillionFD = substr($points_disp, 0, 1);
$oneMillionSD = substr($points_disp, 1, 1);
$oneMillionRange = range(999999, 9999999);

if ($points_disp < 1000){
    echo $points_disp;
} else if (in_array($points_disp, $oneRange)){
    echo $oneFDigit . "." . $oneSDigit . "k";
} else if (in_array($points_disp, $tenRange)){
    echo $tenFDigit . "." . $tenSDigit . "k";
} else if (in_array($points_disp, $hunRange)){
    echo $hunFDigit . "." . $hunSDigit . "k";
} else if (in_array($points_disp, $oneMillionRange)){
    echo $oneMillionFD . "." . $oneMillionSD . "m";
}

2 个答案:

答案 0 :(得分:5)

如果条件始终为false,请使用:

...
} else {
    echo "some value";
}

答案 1 :(得分:3)

我试过这个,只是抛弃了你的范围(),因为我遇到了内存问题。我认为范围是在这里使用的错误函数,因为你会得到一些巨大的数组,你只想知道数字是否在这个数值之间。

注意:新范围数组按此顺序需要minValue和maxValue!

$user_data['points'] = 9999;

$points_disp = $user_data['points'];
$oneFDigit = substr( $points_disp, 0, 1 );
$oneSDigit = substr( $points_disp, 1, 1 );
$oneRange = array( 1000, 9999 );

$tenFDigit = substr( $points_disp, 0, 2 );
$tenSDigit = substr( $points_disp, 2, 1 );
$tenRange = array( 9999, 99999 );
//
$hunFDigit = substr( $points_disp, 0, 3 );
$hunSDigit = substr( $points_disp, 3, 1 );
$hunRange = array( 99999, 999999 );
//
$oneMillionFD = substr( $points_disp, 0, 1 );
$oneMillionSD = substr( $points_disp, 1, 1 );
$oneMillionRange = array( 999999, 9999999 );


if ( $points_disp < 1000 ) {
    echo $points_disp;
} else if ( checkInRange( $points_disp, $oneRange ) ) {
    echo $oneFDigit . "." . $oneSDigit . "k";
} else if ( checkInRange( $points_disp, $tenRange ) ) {
    echo $tenFDigit . "." . $tenSDigit . "k";
} else if ( checkInRange( $points_disp, $hunRange ) ) {
    echo $hunFDigit . "." . $hunSDigit . "k";
} else if ( checkInRange( $points_disp, $oneMillionRange ) ) {
    echo $oneMillionFD . "." . $oneMillionSD . "m";
} else {
    echo "nothing found";
}

function checkInRange( $needle, $range ) {
    $min = $range[0];
    $max = $range[1];

    return ( $needle >= $min && $needle <= $max ) ? true : false;
}