Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to automatically know the name of a field of an array in php?
    primarykey
    data
    text
    <p>I just have a little question, I can't find any answer since I don't know exactly how to formulate it on Google.</p> <p>So I have this array returned from a query:</p> <pre><code>Array ( [0] =&gt; Array ( [aad3177ec0cbced7a15fae003bdd0ff3] =&gt; Array ( [rowid] =&gt; aad3177ec0cbced7a15fae003bdd0ff3 [id] =&gt; 21 [qty] =&gt; 1 [price] =&gt; 176 [name] =&gt; KRUPS YY1305 [image] =&gt; utilities/images/products/p2070396dt.jpg [description] =&gt; Menu simplifié pour une convivialité optimale. [subtotal] =&gt; 176 ) ) ) </code></pre> <p>And I want to get all the information rowid, id, qty ... to store it through a foreach loop in another variable without knowing the name of the second array : 'aad3177ec0cbced7a15fae003bdd0ff3'. I just want to retrieve articles from a cart stored in a database when user logged out.</p> <p>So how can I say something like :</p> <pre><code>echo $myArray['0'][theNumberGoesHereAutomatically]['price']; </code></pre> <p>Ideally, my code would look like that : </p> <pre><code>foreach ($data2 as $cart){ $data = array( 'rowid' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['rowid'], 'id' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['id'], 'qty' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['qty'], 'price' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['price'], 'name' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['name'], 'image' =&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['image'], 'description'=&gt; $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['description'], ); $this-&gt;cart-&gt;insert($data2); $token++; }; </code></pre> <p>without knowing the aad3177ec0cbced7a15fae003bdd0ff3.</p> <p>Any ideas? Thanks :)</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