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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何以給定的格式填充數(shù)組?

如何以給定的格式填充數(shù)組?

PHP
慕后森 2023-06-30 16:07:24
我想形成一個(gè)像這樣的數(shù)組:$routes = [            array("key" => 0, "title" => "All"),            array("key" => 1, "title" => "Web Series"),            array("key" => 2, "title" => "Reality Shows"),            array("key" => 3, "title" => "Singing"),            array("key" => 4, "title" => "Vendors")        ];在這里,標(biāo)題(網(wǎng)絡(luò)連續(xù)劇、真人秀、歌唱)應(yīng)該來(lái)自數(shù)據(jù)庫(kù)的響應(yīng):    $projectTypes = ProjectType::select('project_type_title')->get()->all();如何使用這些值填充像上面這樣的數(shù)組?筆記:array("key" => 0,       "title" => "All") 必須預(yù)定義并且不從數(shù)據(jù)庫(kù)中獲取,只有其他項(xiàng)目類型才會(huì)從數(shù)據(jù)庫(kù)中獲取。我的數(shù)據(jù)庫(kù)包含以下值:array ( 0 => 'Web series', 1 => 'Drama', 2 => 'Movie', )
查看完整描述

1 回答

?
GCT1015

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊

請(qǐng)隨意使用下面的示例


   $projectTypes = [array("key" => 1, "title" => "Web Series"),

        array("key" => 2, "title" => "Reality Shows"),

        array("key" => 3, "title" => "Singing"),

        array("key" => 4, "title" => "Vendors")];


$routes = [["key" => 0, 

      "title" => "All"]];


foreach ($projectTypes as $value) {

    $routes[] = ["key" => $value['key'], "title" => $value['title']];

}

結(jié)果:


Array ( [0] => Array ( [key] => 0 [title] => All ) 

        [1] => Array ( [key] => 1 [title] => Web Series ) 

        [2] => Array ( [key] => 2 [title] => Reality Shows ) 

        [3] => Array ( [key] => 3 [title] => Singing ) 

        [4] => Array ( [key] => 4 [title] => Vendors ) )

編輯:


$projectTypes = ProjectType::select('project_type_title')->get()->all();


$finalResult= [["key" => 0, 

      "title" => "All"]];


foreach ($projectTypes as $key => $value) {

    $finalResult[] = ["key" => $key + 1, "title" => $value];

}


查看完整回答
反對(duì) 回復(fù) 2023-06-30
  • 1 回答
  • 0 關(guān)注
  • 163 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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