This is an example PHP program that demonstrates how to unpack arrays and the effect that it has.
<?php // Create a numerically-indexed array. $saArray1 = ['zero','one','two','three','four']; // Create a second numerically-indexed array. $saArray2 = ['ten','twenty','thirty','forty']; // Unpack those arrays into a third numerically-indexed array (requires PHP 7.4) $saArray3 = ['Father', ...$saArray1, 'Son', ...$saArray2, 'Holy Spirit']; // Display the resulting array foreach($saArray3 as $iKey => $sValue) { echo "{$iKey} => {$sValue}<br />"; } echo "<hr />"; // Create an associative array $saAssoc1 = ['Major1' => 'Isaiah', 'Major2' => 'Daniel']; // Create a second associative array $saAssoc2 = ['Major3' => 'Jeremiah', 'Major4' => 'Ezekiel']; // Unpack those into a third associative array (requires PHP 8.1) - values may be overwritten $saAssoc3 = ['Minor1' => 'Amos', ...$saAssoc1, 'Minor2' => 'Jonah', ...$saAssoc2, 'Minor3' => 'Joel']; // Display the resulting array foreach($saAssoc3 as $iKey => $sValue) { echo "{$iKey} => {$sValue}<br />"; } ?>
© 20072025 XoaX.net LLC. All rights reserved.