将对象值替换为数组

时间:2019-02-25 11:31:01

标签: php

您好,我正在尝试将对象值替换为php中的数组,但在使用foreach或其他php方法时无法访问该对象。

这里是数组,我想进入WP_Term对象以更改分类值

array (
  0 => 
  array (
    'text' => 'Accueil',
    'url' => 'http://docker.localhost:8004',
    'allow_html' => true,
  ),
  1 => 
  array (
    'term' => 
    WP_Term::__set_state(array(
       'term_id' => 113,
       'name' => 'Animation séminaire',
       'slug' => 'animation-seminaire',
       'term_group' => 0,
       'term_taxonomy_id' => 113,
       'taxonomy' => 'decouvrir',
       'description' => '',
       'parent' => 0,
       'count' => 123,
       'filter' => 'raw',
    )),
    10715 => 
    array (
      'taxonomy' => 'test',
    ),
  ),
  2 => 
  array (
    'id' => 396,
  ),
)

预先感谢您的帮助

1 个答案:

答案 0 :(得分:2)

您可以通过在变量中获取数组键,然后分配属性来实现此目的:

$term = $array[1]['term']; # get the obj in arr
$term->taxonomy = 'foo'; # set obj property

echo '<pre>'. print_r($array, 1) .'</pre>'; # print arr - will show updated val
相关问题