I have an array that can contain multidimensional elements. For populating checkboxes from database in the edit-form, I need to check for specific key-value pairs from this array.
The array ($areastools) can look like this:
array:9 [▼
15 => array:2 [▼
0 => 1
1 => 4
16 => 4
45 => array:2 [▶]
47 => 4
50 => array:2 [▶]
51 => 4
]
The first key is the specific area id ($area->pivot->id), and the values are the tool ids ($tool->id).
Currently I have this check, where the checkbox is checked if
(array_key_exists($area->pivot->id, $areastools) &&
($areastools[$area->pivot->id] == $tool->id))
This works for all elements of the array that are not multidimensional. The correct checkboxes are then checked in the edit-form.
But when two tools are added to the same area, the checkboxes for none of these tools are checked, as the condition does not check the values correct if an area has many tools.
I have been searching and trying, but can not find out how to do this. Can anyone please help me?