CKTIS / PHP
Keyword list
Destructure array elements into variables during assignment.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
list($first, , $third) = $row;Destructure array elements into variables during assignment. Skipped positions still consume a numeric index. Explicit keys may select associative fields, but keyed and unkeyed targets cannot be mixed at the same list level. A missing key yields null with a warning in PHP 8.4.
$row=["A","B","C"]; list($a,,$c)=$row; list("qty"=>$n)=["qty"=>4]; echo json_encode([$a,$c,$n]);
["A","C",4]
Examples
<?php
$row=["A","B","C"]; list($a,,$c)=$row; list("qty"=>$n)=["qty"=>4]; echo json_encode([$a,$c,$n]);
Result
["A","C",4]