Войти

PHP - Сортировка масивов

<? function build_sorter($key) { return function ($a, $b) use ($key){ return strnatcmp($a[$key], $b[$key]); }; } usort($arOffer[\'sizes\'], build_sorter(\'SIZE\')); function compare ($v1, $v2) { /* Сравниваем значение по ключу date_reg */ if ($v1["SIZE"] == $v2["SIZE"]) return 0; $zn_1 = preg_replace(\'/[^0-9]/\', \'\', $v1["SIZE"]); $zn_2 = preg_replace(\'/[^0-9]/\', \'\', $v2["SIZE"]); if($zn_1 < $zn_2){ return -1; } else{ return 1; } } usort($arOffer[\'sizes\'], "compare"); ////////////////////////////////////////////////////////////////// function rt($c){ foreach($c as $key=>$mas_2){ $size = preg_replace(\'/[^0-9]/\', \'\', $mas_2[\'SIZE\']); $size_2 = preg_replace(\'/[^A-z]/\', \'\', $mas_2[\'SIZE\']); $b[$size][$size_2]=array(ID=>$mas_2[\'ID\'], SIZE=>$mas_2[\'SIZE\'], NUM=>$size,LET=>$size_2); } ksort($b); foreach($b as $key=>$val){ ksort($b[$key]); } foreach($b as $key => $val){ foreach($val as $inner_key => $inner_val){ $mas[] = array(ID=>$inner_val[\'ID\'], SIZE=>$inner_val[\'SIZE\']); } } return($mas); } ?>
Теги:
php