Q:

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

belongs to collection: PHP array programs with examples

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Original array :
10 20 30 40 50 60
After inserting '#' the array is :
10 20 30 40 # 50 60

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP script to calculate and display averag... >>
<< Write a PHP script to get the First element of the...