Kahlil N Kahlil N - 1 year ago 84
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,

Answer Source

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;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download