array pad function in php - fill-up array to specified length with a defined value

php example code : array_pad function in php - fill-up array to specified length with a defined value

array-pad-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_pad function in php - fill-up array to specified length with a defined value</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_pad function in php - fill-up array to specified length with a defined value">
  <meta name="keywords" content="php, example, code, array, function, array_pad">
  <meta name="description" content="php example code : array_pad function in php - fill-up array to specified length with a defined value">
 </head>
 <body>
  <h3>php example code : array_pad function in php - fill-up array to specified length with a defined value</h3>
  <?php
   /*
    ------------------------------------------------
    let us make an array with some keys and values
    ------------------------------------------------
   */
   $myArray1 = array("key1"=>"value1","key2"=>"value2","key3"=>"value3");
   echo "<p style='background:#ddd; color:red;'>Output of myArray1</p>";
   echo "<pre>";
   print_r($myArray1);
   echo "</pre>";
   /*
    --------------------------------------------------------------------------
    now we want to add 3 more key with value 33 by using array_pad function
    --------------------------------------------------------------------------
   */
   $finalArray = array_pad($myArray1, 6, 33);
   echo "<p style='background:#aaa; color:red;'>Output of finalArray using array_pad function</p>";
   echo "<pre>";
   print_r($finalArray);
   echo "</pre>";
  ?>
 </body>
</html>

php example code : array_pad function in php - fill-up array to specified length with a defined value - output in the browser

No comments:

Post a Comment

leave your comments here..