array_keys()
functionYou can use the PHP array_keys()
function to get all the keys out of an associative array.
Let's try out an example to understand how this function works:
<?php
$cities = array("France"=>"Paris", "India"=>"Mumbai", "UK"=>"London", "USA"=>"New York");
// Get keys from cities array
print_r(array_keys($cities));
?>
You can also use the PHP foreach
loop to find or display all the keys, like this:
<?php
$cities = array("France"=>"Paris", "India"=>"Mumbai", "UK"=>"London", "USA"=>"New York");
// Loop through cities array
foreach($cities as $key => $value){
echo $key . " : " . $value . "<br>";
}
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
in this article, I will share with you h...Check if Array is Empty or null in Javascript
When working in Javascript, many times y...How to find the number of characters in a string using jQuery
Use the jQuery .length property The j...How to install the Apache Web Server on Ubuntu
Apache is open-source and most widely us...Node.js MySQL Create table into Database Server
This article will guide you to how to cr...