1 回答
TA贡献1827条经验 获得超4个赞
请随意使用下面的示例
$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']];
}
结果:
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];
}
- 1 回答
- 0 关注
- 121 浏览
添加回答
举报