php数组检查结果没有任何意义

时间:2015-06-30 05:44:53

标签: php arrays

以下代码:

<?php
$col_names = array('n1','n2','n3','n4','n5');
$values    = array(0,0,'NOW()',0,0);
$i = 0;
while($i<count($col_names)) {
    if($values[$i] == 'NOW()') {
        $qmarks[] = "NOW()";    
    } else {
        $qmarks[] = '?';    
    }    
    $i++;
}
print_r($qmarks);
?>

结果如下:

Array
(
    [0] => NOW()
    [1] => NOW()
    [2] => NOW()
    [3] => NOW()
    [4] => NOW()
)

它应该是这样的:

Array
(
    [0] => ?
    [1] => ?
    [2] => NOW()
    [3] => ?
    [4] => ?
)

有人有想法吗?

1 个答案:

答案 0 :(得分:2)

<?php
$col_names = array('n1','n2','n3','n4','n5');
$values    = array(0,0,'NOW()',0,0);
$i = 0;
while($i<count($col_names)) {
    if($values[$i] === 'NOW()') {
        $qmarks[] = "NOW()";    
    } else {
        $qmarks[] = '?';    
    }    
    $i++;
}
print_r($qmarks);
?>

===改为==