Hello folks! welcome back to a new section of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP array_keys() Function.
The array_keys() function returns the keys, numeric and string, from the input array.
The 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]] );
READ: PHP ereg() Function
Parameter Details
Sr.No | Parameter & 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 )
READ: PHP Regular Expressions
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP array_map() Function.
Feel free to ask your questions where necessary and we 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.
Feel free to ask your questions where necessary and we 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.