Sorting a Multi-Dimentional Array
Script ini berguna untuk melakukan sorting berdasarkan subkey pada array multi dimensi.
function subsort($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = $v[$subkey];
}
asort($b);
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return $c;
}
function subasort($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = $v[$subkey];
}
asort($b);
foreach($b as $key=>$val) {
$c[$key] = $a[$key];
}
return $c;
}
function subarsort($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = $v[$subkey];
}
arsort($b);
foreach($b as $key=>$val) {
$c[$key] = $a[$key];
}
return $c;
}
function subsorti($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
asort($b);
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return $c;
}
function subasorti($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
asort($b);
foreach($b as $key=>$val) {
$c[$key] = $a[$key];
}
return $c;
}
function subarsorti($a,$subkey=0) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
arsort($b);
foreach($b as $key=>$val) {
$c[$key] = $a[$key];
}
return $c;
}
Facebook Comments
Leave a Reply