Get array's key recursively and create underscore separated string

后端 未结 5 754
走了就别回头了
走了就别回头了 2020-11-29 09:06

Right now i got an array which has some sort of information and i need to create a table from it. e.g.

Student{
      [Address]{
              [StreetAddress         


        
5条回答
  •  青春惊慌失措
    2020-11-29 09:09

    function getValues($dataArray,$strKey="")
    {
        global $arrFinalValues;
    
        if(is_array($dataArray))
        {
            $currentKey = $strKey;
            foreach($dataArray as $key => $val)
            {
                if(is_array($val) && !empty($val))
                {   
                    getValues($val,$currentKey.$key."_");
                }
                else if(!empty($val))
                {
                    if(!empty($strKey))
                        $strTmpKey = $strKey.$key;
                    else
                        $strTmpKey = $key;
                    $arrFinalValues[$strTmpKey]=$val;
                }
            }
        }
    }
    

提交回复
热议问题