$cuisines = RestaurantProfile::select('cuisines')->get();
$cuisines_array = array();
foreach ($cuisines as $cuisine) {
$string = implode(",",json_decode($cuisine, true));
$array = explode(",", $string);
foreach ($array as $single) {
if (!in_array($single, $cuisines_array)) {
$cuisines_array[] = $single;
}
}
}
dd($cuisines_array);
我希望$ cuisines_array有类似
的东西array:33 [▼
0 => "Afghani"
1 => "Mughlai"
2 => "Chinese"
3 => "Indian"
4 => "continental"
5 => "south indian"
6 => "mughlai"
但我在屏幕截图中显示:output screenshot
表中的我的美食属性是database table。 任何线索?
答案 0 :(得分:0)
您可以使用array_slice():
...
foreach (array_slice($array, 0, 6) as $single) {
...
array_slice()
返回数组中数组的元素序列 偏移和长度参数