-1

我有一个数组$args

Array ( 
        [0] => stdClass Object ([term_id] => 3 [name] => Default [slug] => default [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => media_category [description] => The default media category. [parent] => 0 [count] => 0 [term_order] => 0 [category_count] => 0 [category_description] => The default media category. [cat_name] => Default [category_nicename] => default [category_parent] => 0 ) 
        [1] => stdClass Object ( [term_id] => 7 [name] => Animals [slug] => animals [term_group] => 0 [term_taxonomy_id] => 7 [taxonomy] => media_category [description] => [parent] => 0 [count] => 1 [term_order] => 0 [category_count] => 1 [category_description] => [cat_name] => Animals [category_nicename] => animals [category_parent] => 0 ) 
        [2] => stdClass Object ( [term_id] => 8 [name] => Characters [slug] => characters [term_group] => 0 [term_taxonomy_id] => 8 [taxonomy] => media_category [description] => [parent] => 0 [count] => 1 [term_order] => 0 [category_count] => 1 [category_description] => [cat_name] => Characters [category_nicename] => characters [category_parent] => 0 ) 
)

当我尝试删除数组的第一项时...

unset($args[0]);

...什么都没发生。知道为什么吗?

4

3 回答 3

1

unset()函数只会删除一个变量,它不会缩小你的数组。

http://php.net/manual/de/function.unset.php

于 2012-05-21T13:44:43.493 回答
1

也许您正在寻找的是:

$first_arg = array_shift($args);  

或者如果你想删除数组中的任意元素:

array_splice($args,0,1)
于 2012-05-21T14:21:47.010 回答
0

你可以使用这样的东西:

foreach($args as $key=>$value){
$args[$key]=get_object_vars($value);
}
unset($args[0]);
于 2012-05-21T14:12:26.143 回答