CopyPastehas never been so tasty!

Get all keys & values from array using array_keys, array_val

by anonymous

  • 0
  • 0
  • 0
77 views

http://codingvilla.com/get-all-keys-and-values-from-array-in-php-single-article-685.aspx

Code:

 

<?php

$name["T"]="Tahreem";

$name["R"]="Rizwan";

$name["F"]="Fatima";

$name["M"]="Misbah";

print_r(array_keys($name));

?>

 

Output:

 

Array ( [0] => T [1] => R [2] => F [3] => M )

 

Explanation:

 

In the above code we have declared $name array type variable and initialize it by index. First index name has value Tahreem. Second index name R have value Rizwan. Third index name F have value Fatima. Fourth index name M have value Misbah. Then pass that array to array_keys function of php that returns all the keys of array. For example in the above code output 0=>T means ‘0’ index name is T and 1=>R means ‘1’ index name is R.

 

 

Add A Comment: