Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With php 5, whip up a quick class to model it, then use asort to sort them and, if you want, move them into another array. Like this:</p> <pre><code>class MyThing { private orderID; private prodName; private quantity; private cartID; private isPack; public get_OrderID() {return $this-&gt;orderID;} public load_values_from_array(array &amp;$data) { $this-&gt;orderID=$data['orderId']; $this-&gt;prodName=$data['prodName']; /* ... go on ...*/ } public static order(MyThing &amp;$a, MyThing &amp;$b) { if($a-&gt;orderID &gt; $b-&gt;orderID) return 1; else if($a-&gt;orderID &lt; $b-&gt;orderID) return -1; else return 0; } } </code></pre> <p>Create the array, fill it up with your classes using "load_values_from_array" and order it like this:</p> <p>uasort($my_array, array('MyThing', 'order'));</p> <p>If you want to have the key values as the orderID you can do this:</p> <pre><code>$order_key_id=array(); foreach($my_array as $key =&gt; &amp;$value) { $orderid=$value-&gt;get_orderID(); if(!isset($order_key_id[$orderid])) $order_key_id[$orderid]=array(); $order_key_id[$orderid][]=$value; } </code></pre> <p>Of course, you can skip the class part and go nuts on it using code that looks and behaves like the last bit, like this:</p> <pre><code>$order_key_id=array(); foreach($my_array as $key =&gt; &amp;$value) { $orderid=$value['orderID']; if(!isset($order_key_id[$orderid])) $order_key_id[$orderid]=array(); unset($value['orderID']; $order_key_id[$orderid][]=$value; } </code></pre> <p>I did not test the code, but I think you'll catch the drift.</p>
    singulars
    1. This table or related slice is empty.
    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. 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