启用功能式语法,例如 $list->filter($cb)->map($cb2)

v0.1.0 2019-06-04 03:03 UTC

This package is not auto-updated.

Last update: 2024-09-19 03:37:48 UTC


README

问题

你有一个数组,你需要删除所有非数字项,并将其他所有项加倍。

解决方案

$a = kdaviesnz/utilities/lists([null, "apple", 1,2,3]);

$result = $a->filter(function($item) { return is_numeric($item) })->map(function($item) { return $item * 2 } )();

$a_parsed = $result();

查看测试文件 listsTest.php

lists