
Get the first key of an array in php
Answers 1
-
Get the first key of an array using array_key_first() function
<?php $array = ['first_key' => 1, 'second_key' => 2, 'third_key' => 3]; if (!function_exists('array_key_first')) { function array_key_first(array $array) { foreach($array as $key => $unused) { return $key; } return NULL; } } $firstKey = array_key_first($array); var_dump($firstKey);
0Using this code snippet you will get the first key of an array in php. It returns the first key of array if array is not empty else it returns null. This function in php will get the first key from an array without affecting the internal array pointer.
Random Code Snippet Queries: Php
- How to remove duplicate values from Array in PHP
- Convert comma-separated string into array in PHP
- Convert an array to string in PHP
- Convert string to sha512 in PHP
- You are trying to access an array as object
- Page view counter in PHP
- How to increment variable value by 1 in php
- User-defined functions in php
- Show errors in php
- PHP number format indian currency
- Required parameter $originalDate follows optional parameter $format
- How to add new item to array in PHP
- How to display data in ckeditor?
- Array to string conversion error in PHP
- How to get image tmp_name in PHP
- If statement with multiple conditions in php
- How to check file is an image in php
- How to displaying ckeditor save HTML data from SQL database
- How to check If an element exists in Array in php
- Delay code execution in PHP
- How to get date with day, month, year, weekdays from string "2021/08/12" in php
- Shorthand for isset() in php