How To Get All the Keys Out of an Array?

deepak singh
Posts: 686
Joined: Fri Sep 30, 2016 4:19 pm

How To Get All the Keys Out of an Array?

Postby deepak singh » Sat Oct 01, 2016 5:33 pm

How To Get All the Keys Out of an Array?

rameshkhd
Posts: 1279
Joined: Sun Aug 28, 2016 10:45 am

Re: How To Get All the Keys Out of an Array?

Postby rameshkhd » Sat Oct 01, 2016 5:34 pm

Function array_keys() returns a new array that contains all the keys of a given array. Here is a PHP script on how to use array_keys():
<?php
$mixed = array();
$mixed["Zero"] = "PHP";
$mixed[1] = "Perl";
$mixed["Two"] = "Java";
$mixed["3"] = "C+";
$mixed[""] = "Basic";
$mixed[] = "Pascal";
$mixed[] = "FORTRAN";
$keys = array_keys($mixed);
print("Keys of the input array:\n");
print_r($keys);
?>
This script will print:
Keys of the input array:
Array
(
[0] => Zero
[1] => 1
[2] => Two
[3] => 3
[4] =>
[5] => 4
[6] => 5
)


Return to “PHP”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest