1

Head and tail sugar syntax

Hi, It could be nice if will have something like in Erlang. ```php function sum([$head|$tail]){ if(empty($tail)){ return $head; } return $head + sum($tail); } echo sum( [1, 2, 3, 4] ); // 10 ``` This combined with a little of pattern matching (with the function signature) would be very nice ! Like : ```php // When we receive an empty list function sum([]){ return 0; } // Normal case function sum([$head|$tail]){ return $head + sum($tail); } echo sum( [1, 2, 3, 4] ); // 10 ``` Thoughts ?
Exception · 2 months ago

Cryde · 2 months ago