usort($mydata, buildSorter(3)); function buildSorter($key) { return function ($a, $b) use ($key) { return strnatcmp($a[$key], $b[$key]); }; }