key,value pair를 보존한 섞기 추가

This commit is contained in:
2018-06-23 02:22:49 +09:00
parent 85b7e6ad17
commit 469fea321d
+17
View File
@@ -281,6 +281,23 @@ class Util extends \utilphp\util
return $dict;
}
/**
* key=>value pair를 보존한 섞기
*/
public static function shuffle_assoc(&$array) {
$keys = array_keys($array);
shuffle($keys);
foreach($keys as $key) {
$new[$key] = $array[$key];
}
$array = $new;
return true;
}
/**
* 0.0~1.0 사이의 랜덤 float