❮ PHP Array Reference Show ExampleReturn an array containing the keys: <?php Try it Yourself » Definition and UsageThe array_keys() function returns an array containing the keys. Syntaxarray_keys(array, value, strict) Parameter Values
Technical Details
More ExamplesExampleUsing the value parameter: <?php Try it Yourself » ExampleUsing the strict parameter, false: <?php Try it Yourself » ExampleUsing the strict parameter, true: <?php Try it Yourself » ❮ PHP Array Reference PHP: Return all the keys of an arrayThe array_keys() function is used to get all the keys or a subset of the keys of an array. Version: (PHP 4 and above) Syntax: array_keys(input_array, search_key_value, strict) Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned. Parameters:
Return value: An array of all the keys of input_arrray. Value Type: Array Example - 1:
Output: Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry ) Pictorial Presentation: View the example in the browser Example - 2 : <?php $array1=array("Orange","Apple","Banana","Apple"); print_r(array_keys($array1,"Apple")); ?> Output : Array ( [0] => 1 [1] => 3 ) View the example in the browser Practice here online : See also PHP Function Reference Previous:array_key_exists PHP: Tips of the DayPHP: Javascript Equivalent to PHP Explode() This is a direct conversion from your PHP code: //Loading the variable var mystr = '0000000020C90037:TEMP:data'; //Splitting it with : as the separator var myarr = mystr.split(":"); //Then read the values from the array where 0 is the first //Since we skipped the first element in the array, we start at 1 var myvar = myarr[1] + ":" + myarr[2]; // Show the resulting value console.log(myvar); // 'TEMP:data' Ref : https://bit.ly/3hSDp4q (PHP 5 >= 5.2.0, PHP 7, PHP 8) array_fill_keys — Fill an array with values, specifying keys Descriptionarray_fill_keys(array Parameterskeys Array of values that will be used as keys. Illegal values for key will be converted to string. value Value to use for filling Return ValuesReturns the filled array ExamplesExample #1 array_fill_keys() example
The above example will output: Array ( [foo] => banana [5] => banana [10] => banana [bar] => banana ) See Also
sergli at nigma dot ru ¶ 10 years ago
atul dot kr_singh at hotmail dot com ¶ 9 years ago
ray.paseur sometimes uses gmail ¶ 5 months ago
Scratchy ¶ 14 years ago
manavchugh988 at gmail dot com ¶ 3 months ago
bananasims at hotmail dot com ¶ 15 years ago
matrebatre ¶ 14 years ago
phydeaux ¶ 14 years ago
ntd at entidi dot it ¶ 6 years ago
taylanaktepe at yahoo dot com ¶ 8 years ago
How get key from value in array in PHP?PHP: array_keys() function
The array_keys() function is used to get all the keys or a subset of the keys of an array. Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned. Specified array.
How can we get particular data from array in PHP?Answer: Use the Array Key or Index
If you want to access an individual value form an indexed, associative or multidimensional array you can either do it through using the array index or key.
What is array_keys () used for?The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys. Parameters: The function takes three parameters out of which one is mandatory and other two are optional.
What is $Key in PHP?Return Values ¶
The key() function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key() returns null .
|