I want to perform Destructuring in php just like in javascript code below:
[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(a,b,rest);
Output:
10 20 [ 30, 40, 50 ]
How can I preform that operation in php?
My php code is:
<?php
$array = [10, 20, 30, 40, 50];
// Using the list syntax:
//list($a, $b, $c[]) = $array;
// Or the shorthand syntax:
[$a, $b, $c[]] = $array;
echo "$a<br>$b<br>";
print_r ($c);
?>
Which prints:
10
20
Array ( [0] => 30 )
But I want "[ 30, 40, 50 ]" in $c