Friday, October 23, 2020

PHP array_keys() Function



Hello dear readers! welcome back to another section of our tutorial on PHP. In this tutorial, we will be studying about the PHP Function array_keys().

PHP array_keys() function returns the keys, numeric and string, from the input array.

Syntax

Following below is the syntax to use this function -

array_keys ( $input [, $search_value [, $strict]] );


Parameter Details

Sr.NoParameter & Description
1

input(Required)

It specifies an array.

2

search_value(Required)

You can specify a value, then only the keys with this value are returned.

3

strict

Optional. Used with the value parameter.


Return Value

It returns the keys, numeric and string, from the input array.

Example

Try out the below example -

<?php
   $input = array("a"=>"Monkey","b"=>"Cat","c"=>"Dog");
   print_r(array_keys($input));
   
   $input = array("a"=>"Monkey","b"=>"Cat","c"=>"Dog");
   print_r(array_keys($input,"Dog"));
   
   $input = array(10,20,30,"10");
   print_r(array_keys($input,"10",false));
?> 

Output

When the above code is executed, it will produce the following result -

Array ( [0] => a [1] => b [2] => c ) Array ( [0] => c ) Array ( [0] => 0 [1] => 3 )


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we will discuss about PHP array_map() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.