Note that there are some explanatory texts on larger screens.

plurals
  1. POphp - Convert object to an array
    primarykey
    data
    text
    <p>I have an array. Here is the <code>var_dump</code> of that array.</p> <pre><code>array (size=2) 0 =&gt; object(stdClass)[266] public 'term_id' =&gt; string '4' (length=1) public 'name' =&gt; string 'Test' (length=4) public 'slug' =&gt; string 'test' (length=4) public 'term_group' =&gt; string '0' (length=1) public 'term_taxonomy_id' =&gt; string '4' (length=1) public 'taxonomy' =&gt; string 'filter' (length=6) public 'description' =&gt; string '' (length=0) public 'parent' =&gt; string '0' (length=1) public 'count' =&gt; string '0' (length=1) 1 =&gt; object(stdClass)[277] public 'term_id' =&gt; string '5' (length=1) public 'name' =&gt; string 'test2' (length=5) public 'slug' =&gt; string 'test2' (length=5) public 'term_group' =&gt; string '0' (length=1) public 'term_taxonomy_id' =&gt; string '5' (length=1) public 'taxonomy' =&gt; string 'filter' (length=6) public 'description' =&gt; string '' (length=0) public 'parent' =&gt; string '0' (length=1) public 'count' =&gt; string '0' (length=1) </code></pre> <p>Now I would like to convert that array like this.</p> <pre><code>$choices = array( array('label' =&gt; 'Test','value' =&gt; 'test'), array('label' =&gt; 'test2','value' =&gt; 'test2'), ) </code></pre> <p>Please note: I mapped keys like this in the <code>choices</code> array</p> <pre><code> name key as label slug key as value </code></pre> <p>Can someone tell me how to achieve this?</p> <h2>Update:</h2> <p>This is what I tried so far.</p> <pre><code>foreach ( $filters as $filter ) { $filterarr[] = "array('label' =&gt; '". $filter-&gt;name ."' ,'value' =&gt; '". $filter-&gt;slug ."' )"; } $choices = array($filterarr); </code></pre> <p>But its not working as expected. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload