Source Code:
(back to article)
<?php // Example 1 $myArray = ["apple", "banana", "cherry"]; list($fruit1, $fruit2, $fruit3) = $myArray; echo $fruit1 . ", " . $fruit2 . ", " . $fruit3 . PHP_EOL; // Output: apple, banana, cherry // Example 2 $myOtherArray = ["John", "Doe", "25"]; list($firstName, $lastName, $age) = $myOtherArray; echo "Name: " . $firstName . " " . $lastName . ", Age: " . $age; // Output: Name: John Doe, Age: 25
Result:
Report an issue