array key function - returns the index of the current array position

array key function - returns the index of the current array position

array-key-function-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 key function - returns the index of the current array position</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 key function - returns the index of the current array position">
  <meta name="keywords" content="php, example, code, array, function, in_array">
  <meta name="description" content="array key function - returns the index of the current array position">
  <style>
   h2, h3, h4{background:#bbb; color:#000078;}
   h2{ padding:3px; margin:3px; font-size:20px;}
   h3{ padding:2px; margin:2px; font-size:18px;}
   h4{ padding:2px; margin:2px; font-size:15px;}
   body{ background:#FFFFFe;}
  </style>
 </head>
 <body>
  <h2>array key function - returns the index of the current array position</h2>
  <pre>
   <?php
    /*
     --------------------------------------------------------------
     lets make an array and fill it up with some values
     --------------------------------------------------------------
    */
    $myArray = array("apple", "book", "cat", "zoo");
    echo "<h4>Output of myArray</h4>";
    print_r($myArray);
    /*
     --------------------------------------------------------------------------------------
     we want to get the key of the current array pointer by using array key function
     --------------------------------------------------------------------------------------
    */
    $currentArrayKey = key($myArray);
    echo "<h3>Output using array key function</h3>";
    print "$"."currentArrayKey = ".$currentArrayKey;
   ?>
  </pre>
 </body>
</html>

array key function - returns the index of the current array position - output in the browser

No comments:

Post a Comment

leave your comments here..