我想从类别ID使用switch case
像这样生成css类名称。奇怪的问题比较交换机内的数字
我在开关情况下有很多条件,但是我们只会看这个作为它创建奇怪的输出。
示例代码:
<?php
$value = '907';//base value
$value_array = str_split($value);//create array of string, if its int.
var_dump($value_array);//debug whats in array
switch($value_array[0]){
case 9:
$final = 'i came inside 9';
if($value_array[1].$value_array[2] == 07){
//check whther last 2 digits are 07
$final = 'i came inside 907';
}else if($value_array[1].$value_array[2] == 09){
//chcek whether last 2 digits are 09
$final = 'i came inside 909';
}
break;
}
echo $final;
上面的代码使输出[$value is 907]
:
array(3) {
[0]=>
string(1) "9"
[1]=>
string(1) "0"
[2]=>
string(1) "7"
}
i came inside 907
这是正确的行为。但如果我将基准值从907改为909,则输出为[$value is 909]
。
array(3) {
[0]=>
string(1) "9"
[1]=>
string(1) "0"
[2]=>
string(1) "9"
}
i came inside 9
输出应该是i came inside 909
。
这是为什么?
它为什么在
907
而不是909
上工作,即使两者的数据类型相同?我知道他们是字符串,我应该比较字符串和字符串,但为什么它与一个例子,而不是与另一个例子?