note 117532 deleted from array.sorting by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:53:17 +0000 |
| Subject: | note 117532 deleted from array.sorting by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213787@lists.php.net to get a copy of this message | ||
Note Submitter: monicse09ku at yahoo dot com
----
// takes an array and desired key value and returns an array
// searches through an array for a given key, if found the key that row is made the first row and
the other rows are inserted accordingly.
// the facility of this function is to get the value with a specific key of an array as the first
value.
/////////////////////////////// function starts //////////////////////////////
function dksort($array, $case){
if(array_key_exists($case,$array)){
$a[$case] = $array[$case];
foreach($array as $key=>$val){
if($case==$key){
}else{
$a[$key] = $array[$key];
}
}
}
return $a;
}
$d = array(
'22'=>'jdfhgjfd',
'33'=>'jdfhgjfd',
'11'=>'jrtyrjfd',
'55'=>'jrtydairjfd',
'77'=>'jopo',
'99'=>'jrtasajfd',
'44'=>'jopasdwo',
'88'=>'hdgatyuyuiuy'
);
$c = dksort($d, '55');
print_r($c);
////////////////////////// function ends ////////////////////////////////////////