0

I have similar problem, which is here: solved Problem

But I would like to get such an array in return as final result for this demo array in 1.

thanks a lot!

return array I would like to get:

    [0] => "0.name "
    [1] => "0.id "
    [2] => "0.phone "
    [3] => "0.Base.city "
    [4] => "0.EBase.city "
    [5] => "0.Qty "
    [6] => "1.name "
    [7] => "1.id "
    [8] => "1.phone "
    [9] => "1.Base.city "
    [10]=> "1.EBase.city "
    [11]=> "1.Qty "

I have tried this: But does not work:

        function array_flat(array $myarr)            
        {            
            $myline = "";            
            foreach ($myarr as $key => $value)            
                {            
                if ( $myline == "" ){$myline=sprintf("%s",$myarr[$key]);}            
                else {$myline=sprintf("%s%s",$myline,$myarr[$key]);}            
                }            
            return array($myline);            
        }            

        function array_keys_multi(array $array)            
        {            
            $keys = array();            

            foreach ($array as $key => $value) {            
            $keys[] = $key;            

            if (is_array($value)) {            
                $keys = array_merge($keys, array_keys_multi($value));            
            }            
                else {            
                    $keys = array_flat($keys);            
                }            

            }            

            return $keys;            
        }            

Moreover I have found this:Maybe it could help to solve my request: get all path of an array

Walter Schrabmair
  • 1,251
  • 2
  • 13
  • 26

2 Answers2

2

Yes this link did what I wanted: Solution

             function getKeyPaths(array $tree, $glue = '_')                    
             {                                                                 
                 $paths = array();                                             
                 foreach ($tree as $key => &$mixed) {                          
                     if (is_array($mixed)) {                                   
                         $results = getKeyPaths($mixed, $glue);                
                         foreach ($results as $k => &$v) {                     
                             $paths[$key . $glue . $k] = $v;                   
                         }                                                     
                         unset($results);                                      
                     } else {                                                  
                         $paths[$key] = $mixed;                                
                     }                                                         
                 }                                                             

                 return $paths;                                                
             }                                                                 

to call it by:

     print_r(getKeyPaths($jsonquotesum));
Walter Schrabmair
  • 1,251
  • 2
  • 13
  • 26
  • Hi @Walter, though the link may have helped you, posting the solution (the code) that made it work for you in here would help others in the future. Especially since the link contains multiple code blocks ;) – rkeet Sep 13 '17 at 14:24
  • @Nukeface thanks for trying to help, but I was faster (in searching the web :) ) – Walter Schrabmair Sep 13 '17 at 16:17
0

Use array_key(). You will get all the keys. doc here:

http://php.net/manual/fr/function.array-keys.php

Jilu
  • 197
  • 1
  • 14