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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. $original = array( '10','20','30','40','50','60' );
  3. echo 'Original array : '."<br>";
  4. foreach ($original as $x)
  5. {echo "$x ";}
  6. $inserted = '#';
  7. array_splice( $original, 4, 0, $inserted );
  8. echo " <br> After inserting '#' the array is : "."<br>";
  9. foreach ($original as $x)
  10. {echo "$x ";}
  11. echo "<br>"
  12. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts