Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed the array at index zero in some different manner
    primarykey
    data
    text
    <pre><code>$i=0; foreach($tagss as $tagdetails) { if($i==0) $tags_array[]["00"]=array("id"=&gt;$i,"name"=&gt;"all","type"=&gt;"gift_finder","parent_id"=&gt;null,"url"=&gt;"all","readonly"=&gt;"0","deleted"=&gt;"0"); $tags_array[][$tagdetails-&gt;id]=array("id"=&gt;$tagdetails-&gt;id,"name"=&gt;$tagdetails-&gt;title,"type"=&gt;"gift_finder","parent_id"=&gt;null,"url"=&gt;$tagdetails-&gt;title,"readonly"=&gt;"0","deleted"=&gt;"0"); $i++; } echo json_encode($tags_array); </code></pre> <p>my out put of above code is :-</p> <pre><code>[{"00":{"id":0,"name":"all","type":"gift_finder","parent_id":null,"url":"all","readonly":"0","deleted":"0"}},{"1":{"id":"1","name":"Adventure","type":"gift_finder","parent_id":null,"url":"Adventure","readonly":"0","deleted":"0"}},{"2":{"id":"2","name":"cool","type":"gift_finder","parent_id":null,"url":"cool","readonly":"0","deleted":"0"}}] </code></pre> <p>that is the right but i want the out put like (just need 0 instead of 00) so i tried :-</p> <pre><code> $i=0; foreach($tagss as $tagdetails) { if($i==0) $tags_array[]["0"]=array("id"=&gt;$i,"name"=&gt;"all","type"=&gt;"gift_finder","parent_id"=&gt;null,"url"=&gt;"all","readonly"=&gt;"0","deleted"=&gt;"0"); $tags_array[][$tagdetails-&gt;id]=array("id"=&gt;$tagdetails-&gt;id,"name"=&gt;$tagdetails-&gt;title,"type"=&gt;"gift_finder","parent_id"=&gt;null,"url"=&gt;$tagdetails-&gt;title,"readonly"=&gt;"0","deleted"=&gt;"0"); $i++; } echo json_encode($tags_array); </code></pre> <p>ouput of the above code :-</p> <pre><code>[[{"id":0,"name":"all","type":"gift_finder","parent_id":null,"url":"all","readonly":"0","deleted":"0"}],{"1":{"id":"1","name":"Adventure","type":"gift_finder","parent_id":null,"url":"Adventure","readonly":"0","deleted":"0"}},{"2":{"id":"2","name":"cool","type":"gift_finder","parent_id":null,"url":"cool","readonly":"0","deleted":"0"}}] </code></pre> <p>that is logically right that it is put the first element in the array and treat next element at first index but i need 0 index separately </p> <p>Any suggestion please thanks in advance .</p> <p>in summary I need </p> <pre><code>[{"0":{"id":0,"name":"all","type":"gift_finder","parent_id":null,"url":"all","readonly":"0", "deleted":"0"}}, {"1":"id":"1","name":"Adventure","type":"gift_finder","parent_id":null,"url":"Adventure","readonly":"0","deleted":"0"}}, {"2":"id":"2","name":"cool","type":"gift_finder","parent_id":null,"url":"cool","readonly":"0","deleted":"0"} }] </code></pre>
    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