Write a PHP script that inserts a new item in an array in any position

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?php
$original = array( '10','20','30','40','50','60' );
echo 'Original array : '."<br>";
foreach ($original as $x) 
{echo "$x ";}
$inserted = '#';
array_splice( $original, 4, 0, $inserted ); 
echo " <br> After inserting '#' the array is : "."<br>";
foreach ($original as $x) 
{echo "$x ";}
echo "<br>"
?>

Result

Write a PHP script that inserts a new item in an array in any position
Write a PHP script that inserts a new item in an array in any position

Leave a Comment