i've been trying to figure out how to make a foreach loop on a multi-dimesial array but sadly with no luck, i have the below array
$levels = [
'A' => [
'xx' => null,
'yy' => 0
],
'B' => [
'xx' => 1,
'yy' => 100
],
'C' => [
'xx' => 3,
'yy' => 250
],
'D' => [
'xx' => 6,
'yy' => 500
]
];
the xx & yy are columns in a table and am simply trying to assign some values to both of them like so
foreach ($levels as $level => $info) {
foreach ($info as $key => $value) {
Level::create([
'name' => $level,
'xx' => $value,
'yy' => $value
]);
}
}
but this doesnt work and it creates a duplicated entries :(.
create()method, so please show it.foreach, in the first foreach just use$info['xx']and$info['yy']foreachis just all you need, glad this helped