0

Hello i'm trying to replace an object value into array in php but I can't access to the object while using foreach or other php method.

Here is the array and I would like to go inside the WP_Term object to change the taxonomy value

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,
  ),
)

Thank you in advance for your help

0

1 Answer 1

2

You can do this by getting the array key in a variable and then assign the property:

$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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.