It's displaying hello once because your using return. The return ends the loop. Instead try echo 'hello';
Apr 14, 2020
2
Level 2
Problems with Arrays
I'm updating a todo list and there are two tables that are involved in updating any todo. The todos table and a steps table. I've already created the relationships. And to update a todo, I have an update function that looks like this
public function update(TodoCreateRequest $request, Todo $todo)
{
$todo->update([
'title' => $request->title,
'description' => $request->description,
]);
$arrSize = sizeof($request->step);
for ($i=0; $i<=$arrSize; $i++) {
return "hello";
}
}
Here lies the problem. When i do this
dd($request->step);
i get this result
array:3 [▼
0 => "Don't do anything stupid"
1 => "Don't leave your isolation chamber"
2 => "Don't go outside"
]
Also when i try to get the size of $request->step by doing this
sizeof($request->step);
it gives me
3
but when i run the update function it only returns
hello once
instead of returning hello more than once according to the condition in the for loop.
Please or to participate in this conversation.