0

我检索如下 URL

http://localhost/codeigniter/?first=value_on_first_param&second=value_on_second_param

在那个 URL 我有代码来检索在 URL 上有一些 GET 参数的 URL

if( $first = $this->input->get( 'first' )
    && $second = $this->input->get( 'second' )
){

    echo 'first param: '.$first;
    echo '<br />';
    echo 'second param: '.$second;

}

然后我尝试打印分配给某些变量的参数的输出

first param: 1
second param: value_on_second_param

正如我们在上面看到的,我的第一个参数值为 1 而不是 value_on_first_param。为什么?我在这里做错了吗?谢谢。

4

1 回答 1

0

这是因为作业:

你做

$first = 
       $this->input->get( 'first' ) && 
$second = $this->input->get( 'second' ) 

就好像

$first = 
      ( $this->input->get( 'first' ) && 
        $second = $this->input->get( 'second' )
      ) 

所以$first将获得真正的价值。

你必须使用它:

if( ($first = $this->input->get( 'first' ))
    && ($second = $this->input->get( 'second' ) )
){

    echo 'first param: '.$first;
    echo '<br />';
    echo 'second param: '.$second;

}
于 2012-11-29T04:21:58.513 回答