SplArray使用
SplArray 支持链式操作,如:$array->unique()->asort()->keys();
命名空间地址:
use \EasySwoole\Core\Component\Spl\SplArray;
获得默认数组格式:
function getArrayCopy(): array
设置数组中元素:
function set($path, $value): void
如:$config->set(‘database.host’,’127.0.0.1’);
获得值:
function get($path)
$splArray = new SplArray([
'config' => [
'mysql' => [
'name' => 'xxxx',
'host' => 'xxxx',
],
'php' => [
'name' => 'xxxx',
'host' => 'xxxx',
]
]
]);
var_dump($splArray->get('config.mysql.'));
/*
[
'name' => 'xxxx',
'host' => 'xxxx',
]
*/
删除元素:
function delete($key): void
$splArray = new SplArray([
'config' => [
'mysql' => [
'name' => 'xxxx',
'host' => 'xxxx',
],
'php' => [
'name' => 'xxxx',
'host' => 'xxxx',
]
],
'other' => ['i m other']
]);
/*
[ 'other' => ['i m other'] ]
*/
数组去重取唯一的值:
function unique(): SplArray
获取数组中重复的值:
function multiple(): SplArray
按照键值升序:
function asort(): SplArray
按照键升序:
function ksort(): SplArray
自定义排序:
function sort($sort_flags = SORT_REGULAR): SplArray
取得某一列:
function column($column, $index_key = null): SplArray
交换数组中的键和值:
function flip(): SplArray
过滤本数组:
function filter($keys, $exclude = false): SplArray
提取数组中的键:
function keys(): SplArray
提取数组中的值:
function values(): SplArray
清空:
function flush():SplArray