Kahlil N Kahlil N - 5 months ago 46
PHP Question

How do i get the key name out of a multidimensional array

I have an array that looks like this:

[0] => Array
[Super Place] => CC Verse Go 0
[Demented Place] => CC Verse Stop 1

And it want to be able to loop through the array and insert the data into a DB. It's easy enough looping through and finding the value based on the Key, but I also need to insert the Key itself. Can I get the Key name using the value or some other method?

Any help is appreciated.

Many Thanks,


You can do it in below way:-


$array = Array(0 => Array
        'Super Place' => 'CC Verse Go 0',
        'Demented Place' => 'CC Verse Stop 1'

foreach ($array as $arr){
   foreach ($arr as $key=>$value){
      echo $key.'= '.$value;
      echo PHP_EOL;