php array sort

array(4) {
[0] => int(2)
[1] => int(5)
[2] => int(1)
[3] => int(3)
}

:After KRSORT by index key desc
array(4) {
[3] => int(3)
[2] => int(1)
[1] => int(5)
[0] => int(2)
}

:ARSORT – by value desc
array(4) {
[1] => int(5)
[3] => int(3)
[0] => int(2)
[2] => int(1)
}

:array_reverse
array(4) {
[3] => int(3)
[2] => int(1)
[1] => int(5)
[0] => int(2)
}

Recursive filtering array in php

$json = $q->execute(array(),Doctrine::HYDRATE_ARRAY);
$filter_key_array = array(‘is_enabled’,’sortorder’,’deleted_at’,’is_deleted’);

$this->sanitizeJson(&$json[0], $filter_key_array);

————
public function sanitizeJson($array,$filter_key_array){
foreach($array as $key => &$value){
if(is_array($value)){
$value = $this->sanitizeJson($value, $filter_key_array);
}else{
if(in_array($key, $filter_key_array)){
unset($array[$key]);
}
}
}
return $array;
}

tag array sanitizing

$tagList = “tag1, , tag2, tag4 , , , , “;

function sanitizeTagList($tagList){
$rs = preg_replace(“/\s+/”,””,$tagList); // remove blank
$rs = explode(‘,’,$rs); // make string as array
$rs = array_unique($rs); // remove repeated tag
$rs = array_diff($rs,array(“”)); // remove “” element
return $rs;
}
$rs = sanitizeTagList($tagList);
// array(3) => {
[0] => “tag1”,
[1] => “tag2”,
[2] => “tag4”,
}