array sizeof function - count elements of an array

array sizeof function - count elements of an array

array-sizeof-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>array sizeof function - count elements 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="array sizeof function - count elements of an array">
  <meta name="keywords" content="php, example, code, array, function, sizeof">
  <meta name="description" content="array sizeof function - count elements of an array">
  <style>
   h2, h4{background:#aaa; color:#000098;}
   h2{ padding:3px; margin:3px; font-size:23px;}
   h4{ padding:2px; margin:2px; font-size:17px;}
   body{ background:#FFFFFb;}
  </style>
 </head>
 <body>
  <h2>array sizeof function - count elements of an array</h2>
  <pre>
   <?php
    /*
     --------------------------------------------------------------
     let's make an array and fill it up with some values
     --------------------------------------------------------------
    */
    $myArray = array("apple","zoo","cow","book");
    echo "<h4>Output of myArray</h4>";
    print_r($myArray);
    /*
     -------------------------------------------------------------------------------------
     we want to count the number of elements in the array by using array sizeof function
     -------------------------------------------------------------------------------------
    */
    $numberOfElements = sizeof($myArray);
    echo "<h4>Output of numberOfElements in the array using array sizeof function</h4>";
    print "$"."numberOfElements = {$numberOfElements}";
   ?>
  </pre>
 </body>
</html>

array sizeof function - count elements of an array - output in the browser

No comments:

Post a Comment

leave your comments here..