如何找到值并将其用于PHP?
我的目标是这样做:
- 从变量中获取值,
- 值,从变量检查值
- 根据
- 使用新值的
更改为数千个。示例:
$input = 12345
//Code to detect input is in thousands or hundreds
$input = 12345 ==> $change = 12000 / 10000
我的目标是实现$变更,代码可以检测输入并返回该代码是否为数百或数千个等等。
在结合了所有意见之后,我得到的答案是:
$maxBarChart= max($countBarChart1,$countBarChart2,$countBarChart3); //The inputs
$length = strlen(strval($maxBarChart)); // Get the length
//Checks
if($length==1){
$numberBarChart = floor($maxBarChart/1);
$totalBarChart = ($numberBarChart*1)+5;
}
elseif($length==2){
$numberBarChart = floor($maxBarChart/10);
$totalBarChart = ($numberBarChart*10)+50;
}
elseif($length==3){
$numberBarChart = floor($maxBarChart/100);
$totalBarChart = ($numberBarChart*100)+500;
}
elseif($length==4){
$numberBarChart = floor($maxBarChart/1000);
$totalBarChart = ($numberBarChart*1000)+5000;
}
elseif($length==5){
$numberBarChart = floor($maxBarChart/10000);
$totalBarChart = ($numberBarChart*10000)+50000;
}
elseif($length==6){
$numberBarChart = floor($maxBarChart/100000);
$totalBarChart = ($numberBarChart*100000)+500000;
}
elseif($length==7){
$numberBarChart = floor($maxBarChart/1000000);
$totalBarChart = ($numberBarChart*1000000)+5000000;
}
elseif($length==8){
$numberBarChart = floor($maxBarChart/10000000);
$totalBarChart = ($numberBarChart*10000000)+50000000;
}
elseif($length==9){
$numberBarChart = floor($maxBarChart/100000000);
$totalBarChart = ($numberBarChart*100000000)+500000000;
}
elseif($length==10){
$numberBarChart = floor($maxBarChart/1000000000);
$totalBarChart = ($numberBarChart*1000000000)+5000000000;
}
尽管这是粗略的和效率低下的意见,但是这些代码奏效并实现了我的目标,但该帖子却是为了了解地板功能和strlen的想法。
谢谢所有建议并回答我帖子的人。
My goal is to do this :
- Get the value from variable
- Check the value
- Change to thousands depending on the value
- Use the new value.
Example :
$input = 12345
//Code to detect input is in thousands or hundreds
$input = 12345 ==> $change = 12000 / 10000
My Goal is to achieve $change, where the code could detect the input and return whether or not it's in hundreds or thousands and so forth.
The Answer I arrived in after combining all of your opinions :
$maxBarChart= max($countBarChart1,$countBarChart2,$countBarChart3); //The inputs
$length = strlen(strval($maxBarChart)); // Get the length
//Checks
if($length==1){
$numberBarChart = floor($maxBarChart/1);
$totalBarChart = ($numberBarChart*1)+5;
}
elseif($length==2){
$numberBarChart = floor($maxBarChart/10);
$totalBarChart = ($numberBarChart*10)+50;
}
elseif($length==3){
$numberBarChart = floor($maxBarChart/100);
$totalBarChart = ($numberBarChart*100)+500;
}
elseif($length==4){
$numberBarChart = floor($maxBarChart/1000);
$totalBarChart = ($numberBarChart*1000)+5000;
}
elseif($length==5){
$numberBarChart = floor($maxBarChart/10000);
$totalBarChart = ($numberBarChart*10000)+50000;
}
elseif($length==6){
$numberBarChart = floor($maxBarChart/100000);
$totalBarChart = ($numberBarChart*100000)+500000;
}
elseif($length==7){
$numberBarChart = floor($maxBarChart/1000000);
$totalBarChart = ($numberBarChart*1000000)+5000000;
}
elseif($length==8){
$numberBarChart = floor($maxBarChart/10000000);
$totalBarChart = ($numberBarChart*10000000)+50000000;
}
elseif($length==9){
$numberBarChart = floor($maxBarChart/100000000);
$totalBarChart = ($numberBarChart*100000000)+500000000;
}
elseif($length==10){
$numberBarChart = floor($maxBarChart/1000000000);
$totalBarChart = ($numberBarChart*1000000000)+5000000000;
}
Although it's crude and inefficent but the code works and achieved what I was aiming for, the post was made to find out about the floor function and strlen idea.
Thank You Everyone who advised and answered my post.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 floor()函数并除以1000,以获取成千上万的输入数:
相同的方式,您获得数百个数字:
如果结果为0(输入为143,则例如),这意味着其中没有千。您应该除以10,然后用100尝试一下:
您可以以 /10的步骤进行,以尝试数千,数百等。
如果您需要获得其余的,请使用Modulo操作员。
例如,120%100 = 20。此外,12345%10000 = 2345。
Use the floor() function and divide by 1000 to get the number of thousands in your input :
The same way, you get the number of hundreds :
If the result is 0 (with an input of 143 for example), that means there is no thousand in it. You should divide by 10 and try it out with 100 :
You may do the same into a for loop with a step of /10 to try thousands, hundreds etc.
If you need to get the rest, use the modulo operator.
For example, 120 % 100 = 20. Also, 12345 % 10000 = 2345.