Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I got it right, what you need is this:</p> <hr> <p><strong>EDIT:</strong> Just made some tests and got it right this time:</p> <pre><code>$Display_Arr = array(); foreach ($_POST['product'] AS $_1){ if (!array_key_exists($_1['Vendor_ID'], $Display_Arr)){ $Display_Arr[$_1['Vendor_ID']] = array( "Vendor_ID" =&gt; $_1['Vendor_ID'], "Quantity" =&gt; $_1['Quantity'] ); }else{ if(!empty($_1['Quantity'])) $Display_Arr[$_1['Vendor_ID']]["Quantity"] .= ",{$_1['Quantity']}"; } } echo "&lt;pre&gt;"; print_r($Display_Arr); echo "&lt;/pre&gt;"; </code></pre> <p>The main problem was in <code>if (!in_array($_1['vendor_id'], $Display_Arr))</code>. PHP's <code>in_array()</code> checks for given <code>needle</code> in the array <em>values</em>, and we were trying to match to the <code>Vendor_ID</code> value stored in the outer array <em>keys</em>. That was fixed using <code>array_key_exists()</code>.</p> <p><strong>EDIT 2:</strong> I used this for test data:</p> <pre><code>$_POST['product'] = array( 0 =&gt; array( 'Vendor_ID' =&gt; 1, 'Quantity' =&gt; 55 ), 1 =&gt; array( 'Vendor_ID' =&gt; 1, 'Quantity' =&gt; 55 ), 2 =&gt; array( 'Vendor_ID' =&gt; 1, 'Quantity' =&gt; 55 ) , 3 =&gt; array( 'Vendor_ID' =&gt; 3, 'Quantity' =&gt; '' ), 4 =&gt; array( 'Vendor_ID' =&gt; 3, 'Quantity' =&gt; '' ), 5 =&gt; array( 'Vendor_ID' =&gt; 3, 'Quantity' =&gt; '' ), 6 =&gt; array( 'Vendor_ID' =&gt; 4, 'Quantity' =&gt; '' ), 7 =&gt; array( 'Vendor_ID' =&gt; 4, 'Quantity' =&gt; '' ), 8 =&gt; array( 'Vendor_ID' =&gt; 4, 'Quantity' =&gt; '' ) ); </code></pre> <hr> <p>You won't be needing <code>$Tick</code> anymore, as you could use <code>Vendor_ID</code> as keys for the outer array.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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