How to get keys name from array using array helper in PHP Laravel ?

How to get keys name from array using array helper in PHP Laravel ?


tutorials - 5 undefined, 2020

How to get keys name from array using array helper in PHP Laravel ?

Few days ago, I was working on my new Laravel 5.4 application and i require to get keys name from my array. i was thing how we can get it and laravel provide us for to do it. Finally i found array helper function in Laravel docs. There are several array helper function available for array.

I found array_keys() helper for getting keys name from our array. array_keys() will return array of keys. It could be easy to work with keys name in array. So in this example i want to share with you small example using array_keys() helper.

I created one route "myarraykeys" with my $myArray variable, and in this route i used array_keys() helper and get keys array.

Example:

Route::get('myarraykeys', function () {


$myArray = [

'name'=>'Hardik Savani',

'email'=>'itsolutionstuff@gmail.com',

'website'=>'itsolutionstuff.com'

];


$myArrayKey = array_keys($myArray);


dd($myArrayKey);


});

Output:

Array

(

[0] => name

[1] => email

[2] => website

)

Our Sponsors

NodeJS Experts
React Experts
PHP Experts
AngularJS Experts
Aws Experts
Firebase Experts

Top Applications in TutorialStuff

Top Experts In TutorialStuff

Trending On TutorialStuff