【发布时间】:2020-08-29 21:17:34
【问题描述】:
这是我的数据结构:
array:2 [▼
"1.5.8.5.2.44785" => array:2 [▼
0 => {#300 ▶}
1 => {#340 ▶}
]
"1.5.8.5.2.22008" => array:3 [▼
0 => {#405 ▶}
1 => {#445 ▶}
2 => {#487 ▶}
]
]
数组的内行包含一些数据。没什么特别的! 每项任务对于一个工作流程也是唯一的。
我需要打印外部数组键(即内部对象的公共 ID)。然后是数组的每个内部 obj 的一些内容。
所以我在刀片视图中写了一些php代码如下:
@if(is_array($workflows))
@foreach(array_keys($workflows) as $workflowId)
<p class="card-text">workflowid: {{$workflowId}}</p>
@foreach($workflows as $tasks)
@foreach($tasks as $task)
idTask: {{$task->id}}</br>
@endforeach
@endforeach
@endforeach
@else
<p class="card-text">No tasks</p>
@endif
如果我打印dd($tasks),内容就是我所期望的。 - 仅来自外部数组的第一个单元格的任务,因此只有当前工作流Id 的正确任务-
如果我打印dd($task) 相同的内容,内容正是我所期望的......当前任务!
arrays_keys 的结果是好的,打印正确,然后在 ive 内两次相同的输出,和错误的输出,所有任务都被列出,而不仅仅是当前工作流程的一部分,我想知道为什么! !!!
workflowid: 1.5.8.5.2.44785
idTask: 1135102 (right task for this workflowid)
idTask: 1135104 (right task for this workflowid)
idTask: 1135185 (wrong task for this workflowid)
idTask: 1135186 (wrong task for this workflowid)
idTask: example (wrong task for this workflowid)
workflowid: 1.5.8.5.2.22008
idTask: 1135102 (wrong task for this workflowid)
idTask: 1135104 (wrong task for this workflowid)
idTask: 1135185 (right task for this workflowid)
idTask: 1135186 (right task for this workflowid)
idTask: example (right task for this workflowid)
我怎么了?谢谢
【问题讨论】:
标签: php arrays laravel foreach laravel-blade