我有以下代码array_shift不删除数组的第一个元素
echo '<pre>';
print_r($this->region_id);
echo '</pre>';
if(end($this->region_id) != 0){
if($this->region_id[0] == 0){
array_shift($this->region_id);
}
}
echo '<pre>';
print_r($this->region_id);
echo '</pre>';
不知怎的,它不删除数组的第一个元素,因为我的成绩长得一模一样的代码与print_r的
运行后Array
(
[0] => 0
[1] => 30
[2] => 14
)
Array
(
[0] => 0
[1] => 30
[2] => 14
)
代码确实达到了数组移位。
我只是C/P代码的另一种方法,用一个简单的数组替换'$ this-> region_id',它适用于我。 PHP 5.3.2 – robertbasic 2010-07-25 08:54:12
$ this-> region_id由$ _POST ['user'] ['region_id']填充; 当我这样做,它的工作 如果(完($这个 - > REGION_ID)!= 0){ \t \t \t如果($这个 - > REGION_ID [0] == 0){ \t \t \t \t array_shift ($ _POST [ '用户'] [ 'REGION_ID']); \t \t \t \t $ this-> region_id = $ _POST ['user'] ['region_id']; \t \t \t} \t \t} Althoug我仍然不明白为什么其他方法,从0,第一个失败 – Roland 2010-07-25 09:02:40