Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have recently built a class I use for creating and sorting HTML tables of objects, here are a some static methods from it you may find useful for sorting associative arrays. I have removed the self:: reference so you can just use the methods as functions.</p> <p>Usage: <code>$array = array_sort($array, 'sort_key_name');</code></p> <pre><code>function array_sort(&amp;$array) { if(!$array) return $keys; $keys = func_get_args(); array_shift($keys); array_sort_func($keys); usort($array,array("listview","array_sort_func")); return $array; } function array_sort_func($a, $b = NULL) { static $keys; if($b === NULL) return $keys = $a; foreach($keys as $k) { $aval = hod($a, '$a-&gt;' . $k); $bval = hod($b, '$b-&gt;' . $k); // modify string to compate if(!is_numeric($aval)){$aval = strtolower($aval);} if(!is_numeric($bval)){$bval = strtolower($bval);} if($k[0]=='!') { $k=substr($k,1); if($aval!== $bval) { if(is_numeric($aval) and is_numeric($bval)) { return $aval - $bval; } else { return strcmp($bval, $aval); } } } else if($aval !== $bval) { if(is_numeric($aval) and is_numeric($bval)) { $compare = $aval - $bval; if($compare &gt; 0) { return 1; } elseif($comare &lt; 0) { return -1; } } else { return strcmp($aval, $bval); } } } return 0; } function hod(&amp;$base, $path) { $licz = ''; $keys = explode("-&gt;", $path); $keys[0] = str_replace('$', '', $keys[0]); $expression = '$ret = '; $expression.= '$'; foreach ($keys as $key) { if (++$licz == 1) { $expression.= 'base-&gt;'; } else { $expression.= $key.'-&gt;'; } } $expression = substr($expression, 0, -2); $expression.= ';'; eval($expression); return $ret; } </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