php - Laravel 内爆数组
问题描述
我有这个代码:
$category = $product->category;
if(!empty($category->category_id)){
$category = [$category->parent->title,$category->title];
}
它给出的结果如下:
Default Category first level category
我想要的是在和>
之间添加Default Category
first level category
我怎么做?
解决方案
Use php's implode function like this $category = implode(" > ", [$category->parent->title,$category->title]);
, then you will get your desired result.
推荐阅读
- javascript - 图像未在 Vue-bootstrap 中显示
- html - 屏幕渲染时如何聚焦输入
- java - 在 Java 中使用 JEST API 为索引添加别名和删除索引
- php - ErrorException: ZipArchive::close(): 创建临时文件失败: 没有错误
- python - Efficiently produce 64 by 10 matrix from 64 and 10 long vectors in python
- c++ - 为什么 g++ 静态链接不适用于 Windows 中的 sfml?
- r - 根据时间计算事件差异
- android - React Native,未连接任何应用程序。向所有 React Native 应用程序发送“重新加载”失败
- java - 如果@SpringBootTest 无法加载 ApplicationContext,如何使故障安全插件失败
- mysql - SQL Inner Join for 2 parents - Child - SubChild 表自定义查询