⊗ppPmSFLArI 275 of 447 menu

Inserting Array Elements in a Loop in PHP

You can also insert elements while iterating through arrays with a loop:

<?php $arr = [1, 2, 3, 4, 5]; foreach ($arr as $elem) { echo "xxx $elem yyy"; } ?>

Simplify the following code:

<?php $arr = ['a' => 1, 'b' => 2, 'c' => 3]; foreach ($arr as $key => $elem) { echo 'pair: ' . $elem . ' ' . $key . '<br>'; } ?>
byenru