programming-examples/php/Arrays/PHP script that inserts a new item in an array in any position.php

12 lines
299 B
PHP
Raw Permalink Normal View History

2019-11-15 12:59:38 +01:00
<?php
$original = array( '1','2','3','4','5' );
echo 'Original array : '."\n";
foreach ($original as $x)
{echo "$x ";}
$inserted = '$';
array_splice( $original, 3, 0, $inserted );
echo " \n After inserting '$' the array is : "."\n";
foreach ($original as $x)
{echo "$x ";}
echo "\n"
?>