Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel刀片上显示嵌套JSON格式_Php_Json_Laravel - Fatal编程技术网

Php 在Laravel刀片上显示嵌套JSON格式

Php 在Laravel刀片上显示嵌套JSON格式,php,json,laravel,Php,Json,Laravel,JSON格式保存在MySql列中,如下所示: [{id:1},{id:2},{id:3,子项:[{id:4},{id:5}] 我在《拉威尔之刃》中做到了这一点 @php $json = $categories->column; $array= json_decode($json , true); @endphp @foreach ($array as $key => $value) <li>{{ $value["id"] }}</li> @end

JSON格式保存在MySql列中,如下所示:

[{id:1},{id:2},{id:3,子项:[{id:4},{id:5}]

我在《拉威尔之刃》中做到了这一点

@php
  $json = $categories->column;
  $array= json_decode($json , true);
@endphp

@foreach ($array as $key => $value)
  <li>{{ $value["id"] }}</li>
@endphp
我得到了这样的结果

一, 2. 三,


但我不能得到结果。我该怎么办?谢谢你的帮助。

试试这段代码,如果存在,你应该有另一个儿童循环

@php
  $json = $categories->column;
  $array= json_decode($json , true);
@endphp

@foreach ($array as $key => $value)
  <li>{{ $value["id"] }}</li>

    //another loop for children if exists
    @if (isset($value["children"]))
        @foreach ($value["children"] as $child_key => $child_value)
          <li class="childs">{{ $child_value["id"] }}</li>
        @endforeach
    @endif

@endforeach
您的输出将如下所示

一,

二,

三,

四,

五,


试试这段代码,如果存在子循环,您应该有另一个循环

@php
  $json = $categories->column;
  $array= json_decode($json , true);
@endphp

@foreach ($array as $key => $value)
  <li>{{ $value["id"] }}</li>

    //another loop for children if exists
    @if (isset($value["children"]))
        @foreach ($value["children"] as $child_key => $child_value)
          <li class="childs">{{ $child_value["id"] }}</li>
        @endforeach
    @endif

@endforeach
您的输出将如下所示

一,

二,

三,

四,

五,


谢谢你的回答。我尝试了您编写的代码,但出现了一个错误,如未定义索引:children。我该怎么办?@acnci使用isset$value[children]检查数据是否存在。我会更新我的答案,如果你得到了答案,请接受,谢谢你的回答。我尝试了您编写的代码,但出现了一个错误,如未定义索引:children。我该怎么办?@acnci使用isset$value[children]检查数据是否存在。我会更新我的答案,如果您得到答案,请接受,谢谢