第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel:獲取數(shù)據(jù)數(shù)組并使用 For 循環(huán)

Laravel:獲取數(shù)據(jù)數(shù)組并使用 For 循環(huán)

PHP
溫溫醬 2021-08-28 09:01:06
我正在嘗試獲取數(shù)據(jù)數(shù)組并使用 For 循環(huán)。所以我有一個名為“顏色”的數(shù)組,我想用 For 循環(huán)數(shù)組。但我在結(jié)果上遇到了一些麻煩。我已經(jīng)嘗試在 foreach 中更改數(shù)組,但我不知道如何獲得我想要的結(jié)果。結(jié)果 :"data": [        {            "title": "get data users",            "function_name": "selectDataUser",            "function_drop": "selectDataUser",            "type_of_chart": "Pie",            "embed": null,            "created_at": "2019-06-15 03:26:09.000",            "updated_at": null,            "data_chart": [                {                    "name": "Administrator",                    "total": "100",                    "color": "0xFF888888" //color cannot be the same                },                {                    "name": "Staff",                    "total": "100",                    "color": "0xFF888888" //the color must be different                },                {                    "name": "Super Administrator",                    "total": "1",                    "color": "0xFF888888" //this is not result what I want.                }            ],      }  ]我想要這樣的回應(yīng): "data": [            {                "title": "get data users",                "function_name": "selectDataUser",                "function_drop": "selectDataUser",                "type_of_chart": "Pie",                "embed": null,                "created_at": "2019-06-15 03:26:09.000",                "updated_at": null,                "data_chart": [                    {                        "name": "Administrator",                        "total": "100",                        "color": "0xFF000000" //all this color different                    },                    {                        "name": "Staff",                        "total": "100",                        "color": "0xFF444444" //the color different                    },                    {                        "name": "Super Administrator",                        "total": "1",                        "color": "0xFF888888" //this is result what I want.                    }                ],}  ]
查看完整描述

1 回答

?
MM們

TA貢獻1886條經(jīng)驗 獲得超2個贊

$set是數(shù)組,不能作為字符串賦值。我的建議是更改以下代碼:


        for ($i=0; $i < count($data_chart) ; $i++) { 

            $set = $color[$i]; //Get data array color

        }



        foreach($data_chart as $row){

            $row->color = $set;

        }


        $i=0; 

        foreach($data_chart as $row){

            $row->color = $color[$i];

            $i++;

        }

但是如果您的$data_chart計數(shù)超過$color計數(shù),它將返回錯誤,以便更好地處理使用以下代碼:


        $i=0; 

        foreach($data_chart as $row){

            if(isset($color[$i])){

            $row->color = $color[$i];

            $i++; }

            else{

            $i=0;

            }


        }


查看完整回答
反對 回復(fù) 2021-08-28
  • 1 回答
  • 0 關(guān)注
  • 283 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號