title: Key of associative table
body: <p>I have a little problem in my project : I would like display only the key of each array when I click on a element of my list. <a href="https://i.stack.imgur.com/tkwD4.png" rel="nofollow noreferrer">Dump of my table</a></p>
  <p>For example when I click in &quot;Paupiette&quot;, I would like display 0.</p>
  <p>I partially succeeded but when I click in a element, I see only the last key (here &quot;1&quot;).</p>
  <p>Here,you can see the code</p>
  <pre><code>$carts = $cartService-&gt;getCart($user);
  //dump($carts); die;
   
  $mykey = 0;
  foreach($carts as $key =&gt; $value) {
      $mykey = $key;
  }
  dump($mykey);die;
  </code></pre>
  <p>If you have any idea, thank you a lot</p>