array keys function in php - it returns all the keys

php example code : array_keys function in php - it returns all the keys

array-keys-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_keys function in php - it returns all the keys</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_keys function in php - it returns all the keys">
  <meta name="keywords" content="php, example, code, array, function, array_keys">
  <meta name="description" content="php example code : array_keys function in php - it returns all the keys">
 </head>
 <body>
  <h3>php example code : array_keys function in php - it returns all the keys</h3>
  <?php
   /*
    ---------------------------------------------------------------------
    let us make an array with some keys and values
    ---------------------------------------------------------------------
   */
   $myArray = array("key1"=>"value1","key2"=>"value2","key3"=>"value3");
   echo "<p style='background:#aaa; color:red;'>Output of myArray</p>";
   echo "<pre>";
   print_r($myArray);
   echo "</pre>";
   /*
    ---------------------------------------------------------------------
    let us test array_keys function by giving myArray array into it
    ---------------------------------------------------------------------
   */
   echo "<p style='background:#bbb; color:red;'>Output of myArray using array_keys function</p>";
   echo "<pre>";
   print_r(array_keys($myArray));
   echo "</pre>";
   /*
    -------------------------------------------------------------------------
    it seems array_keys function returns an array of keys from given array
    -------------------------------------------------------------------------
   */
   /*
    ---------------------------------------------------------------------------------------
    now, test array_keys function by giving myArray array into it with some filter options
    ---------------------------------------------------------------------------------------
   */
   echo "<p style='background:#ccc; color:red;'>Output of myArray using array_keys function with filter options</p>";
   echo "<pre>";
   print_r(array_keys($myArray, "value2"));
   echo "</pre>";
   /*
    --------------------------------------------------------------------------------
    it seems array_keys function returns [0], it means it is the key of given value
    --------------------------------------------------------------------------------
   */
   /*
    --------------------------------------------------------------------------------
    if the filter options does not exist in the array - it returns an empty array
    --------------------------------------------------------------------------------
   */
  ?>
 </body>
</html>


php example code : array_keys function in php - it returns all the keys - output in the browser

No comments:

Post a Comment

leave your comments here..