首页 > 解决方案 > Laravel 内爆数组

问题描述

我有这个代码:

$category = $product->category;
if(!empty($category->category_id)){
  $category = [$category->parent->title,$category->title];
}

它给出的结果如下:

Default Category first level category 

我想要的是在和>之间添加Default Categoryfirst level category

我怎么做?

标签: phplaravel

解决方案


Use php's implode function like this $category = implode(" > ", [$category->parent->title,$category->title]);, then you will get your desired result.


推荐阅读