Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found this in the <a href="http://php.net/manual/en/function.asort.php" rel="nofollow noreferrer">php documentation comments for asort()</a> See also the <a href="http://php.net/manual/en/function.sort.php" rel="nofollow noreferrer">sort()</a> page, in the comments there are a few good candidates.</p> <pre><code>function named_records_sort($named_recs, $order_by, $rev=false, $flags=0) {// Create 1-dimensional named array with just // sortfield (in stead of record) values $named_hash = array(); foreach($named_recs as $key=&gt;$fields) $named_hash["$key"] = $fields[$order_by]; // Order 1-dimensional array, // maintaining key-value relations if($reverse) arsort($named_hash,$flags=0) ; else asort($named_hash, $flags=0); // Create copy of named records array // in order of sortarray $sorted_records = array(); foreach($named_hash as $key=&gt;$val) $sorted_records["$key"]= $named_recs[$key]; return $sorted_records;} // named_recs_sort() function show_sorted_records($named_recs, $order_by, $rev=false, $flags=0) {$sorted_records=named_records_sort($named_recs, $order_by, $rev, $flags); foreach($sorted_records as $name=&gt;$fields) {echo "&lt;b&gt;$name&lt;/b&gt; "; foreach($fields as $field=&gt;$val) echo "$field = $val "; echo "&lt;br&gt;";} } // show_sorted_records() $girl_friends=array(); $girl_friends["Anna"]= array("born"=&gt;'1989-08-22',"cupsize"=&gt;'B-',"IQ"=&gt;105, "daddy"=&gt;'rich'); $girl_friends["Zoe"] =array("born"=&gt;'1978-03-11',"cupsize"=&gt;'C#',"IQ"=&gt;130, "daddy"=&gt;'poor'); $girl_friends["Lilly"] =array("born"=&gt;'1985-06-16',"cupsize"=&gt;'DD',"IQ"=&gt;90, "daddy"=&gt;'nasty'); $order_by="cupsize"; echo "And the winners are: &lt;br&gt;"; show_sorted_records($girl_friends, $order_by, true); </code></pre>
 

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