WebHow to get all the keys of an associative array in PHP. Topic: PHP / MySQL Prev Next. Answer: Use the PHP array_keys() function. You can use the PHP array_keys() … WebAug 19, 2024 · PHP: Return all the keys of an array The 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, …
PHP Get All Array Keys Starting with Certain String Example
WebJul 16, 2014 · // Create an array containing all of the distinct "service types" // from the $services array $service_types = array (); foreach ($services as $service) { // If we have not yet encountered this entry's "service type", // then we need to add it to our new array if (!in_array ($service ['service_type'], $service_types)) { $service_types [] = … WebJan 4, 2012 · You can use array_keys () to get ALL the keys of an array, e.g. $arr = array ('a' => 'b', 'c' => 'd') $x = array_keys ($arr); would give you $x = array (0 => 'a', 1 => 'c'); Share Follow answered Jan 4, 2012 at 15:35 Marc B 354k 43 417 495 Add a comment 25 Here is another option happy and fruitful 意味
PHP: array_keys - Manual
WebOct 31, 2016 · I thought passing in an array and using the array keys for the variables names could replace the need to pass extra variables into the function, and it worked (I'm sure there is a better way to accomplish this, suggestions welcome). However, I can't seem to get the keys out of the array inside the function. The array: WebNov 4, 2010 · 11 Answers Sorted by: 124 You don't. Your array doesn't have a key [1]. You could: Make a new array, which contains the keys: $newArray = array_keys ($array); echo $newArray [0]; But the value "one" is at $newArray [0], not [1]. A shortcut would be: echo current (array_keys ($array)); Get the first key of the array: WebPHP: Get the key from an array in a foreach loop [duplicate] Ask Question Asked 10 years, 10 months ago Modified 5 months ago Viewed 147k times 36 This question already has answers here: How to loop through an associative array and get the key? (12 answers) Closed 3 years ago. chainsaw timber cutter