SplArray

最后更新于:2022-04-02 02:21:51

[TOC] ## get ``` $data = [ 'fruit' => [ 'apple' => 2, 'orange' => 1, 'grape' => 4 ], 'color' => [ 'red' => 12, 'blue' => 8, 'green' => 6 ] ]; $splArray = new \EasySwoole\Spl\SplArray($data); var_dump($splArray->get('fruit.apple')); //2 ``` ## set ``` $splArray->set('fruit.apple', 3); ``` ## __toString ``` var_dump($splArray->__toString()); //转 json ``` ## unset / delete 效果相同 ``` $splArray->delete('fruit.apple'); ``` ## unique 移除数组中重复的值 ``` $data = [ 'apple' => 2, 'orange' => 1, 'grape' => 2, 'pear' => 4, 'banana' => 8 ]; $splArray = new \EasySwoole\Spl\SplArray($data); var_dump($splArray->unique()->getArrayCopy()); ``` ## multiple 获取数组中重复的值 ``` $data = [ 'apple' => 2, 'orange' => 1, 'grape' => 2, 'pear' => 4, 'banana' => 8 ]; $splArray = new \EasySwoole\Spl\SplArray($data); var_dump($splArray->unique()->multiple()); ``` ## column ``` var_dump($splArray->column('apple')->getArrayCopy()); ``` ## flip 键值对 ## toXML 转成 xml
';