DEV Community

Morcos Gad
Morcos Gad

Posted on • Edited on

Tips in php 8

Let's talk about some interesting points in php8 :-

Array unpacking also supports string keys

$array1 = ["a" => 1];
$array2 = ["b" => 2];
$array = ["a" => 0, ...$array1, ...$array2];
var_dump($array); // ["a" => 1, "b" => 2]
Enter fullscreen mode Exit fullscreen mode

The new array_is_list function

$list = ["a", "b", "c"];
array_is_list($list); // true
$notAList = [1 => "a", 2 => "b", 3 => "c"];
array_is_list($notAList); // false
$alsoNotAList = ["a" => "a", "b" => "b", "c" => "c"];
array_is_list($alsoNotAList); // false
Enter fullscreen mode Exit fullscreen mode

I hope it helps everyone.

Top comments (0)