array push function in php - push element into the end of an array

php example code : array_push function in php - push element into the end of an array

array-push-example-in-php.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>php example code : array_push function in php - push element into the end of an array</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="php example code : array_push function in php - push element into the end of an array">
  <meta name="keywords" content="php, example, code, array, function, array_push">
  <meta name="description" content="php example code : array_push function in php - push element into the end of an array">
 </head>
 <body>
  <h3>php example code : array_push function in php - push element into the end of an array</h3>
  <?php
   /*
    ------------------------------------------------
    let us make an array with some keys and values
    ------------------------------------------------
   */
   $myArray1 = array("key1"=>"value1","key2"=>"value2","key3"=>"value3");
   echo "<p style='background:#aaa; color:red;'>Output of myArray1</p>";
   echo "<pre>";
   print_r($myArray1);
   echo "</pre>";
   /*
    -----------------------------------------------------------------------------------
    now we want to add an element to the end of the array by using array_push function
    -----------------------------------------------------------------------------------
   */
   $numberOfElements = array_push($myArray1, "modon");
   echo "<p style='background:#ccc; color:red;'>Output of numberOfElements using array_push function</p>";
   echo "<pre>";
   print $numberOfElements;
   echo "</pre>";
   /*
    -----------------------------------------------------------------------------------
    thus finaly the array will be ..
    -----------------------------------------------------------------------------------
   */
   echo "<p style='background:#eee; color:red;'>Output of myArray1 after array_push function</p>";
   echo "<pre>";
   print_r($myArray1);
   echo "</pre>";
  ?>
 </body>
</html>

php example code : array_push function in php - push element into the end of an array - output in the browser

No comments:

Post a Comment

leave your comments here..