PHP multidimensional array decomposition

前端 未结 2 1571
执笔经年
执笔经年 2020-12-22 13:33

I have a PHP Sql results, table looks like:

It appears as:

[id]|test1|data|voice
1|0|0|-1
2|0|1|0
3|0|-2|-1

Print_r of the ar

相关标签:
2条回答
  • 2020-12-22 14:02

    Considering your source array name as $Arr , Try out below code

    foreach($Arr as $valArr)
    {
        $index = 0;
        foreach($valArr[0] as $k => $v)
        {
            $newArr[$index]["name"] = $k;
            $newArr[$index]["val"][ ] = $v;
            $index++;
        }
    }
    
    echo "<pre>"; print_r($newArr);
    
    0 讨论(0)
  • 2020-12-22 14:21

    use this and do modifications if neded

    SELECT *
    FROM `table_name`
    GROUP BY `test1` , `data` , `voice`
    LIMIT 0 , 30
    
    0 讨论(0)
提交回复
热议问题