-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 に答える