after trying to solve this with multiple foreach loops I still cant figure out how to map $arr
to $arr_mapped
I need to explode the keys of $arr
to get an element with up to three new keys to create $arr_mapped
<?php
$arr = [
'abc:quantity' => 1,
'abc:variant' => 'blue',
'xyz:quantity' => 2,
'foo:quantity' => null
];
$arr_mapped = [
[
'id' => 'abc',
'quantity' => 1,
'variant' => 'blue'
],
[
'id' => 'xyz',
'quantity' => 2
]
];
background: I want to let a user bulk add predefined shopping items in a <form>
I’m Using the Kirby Merx Shop Plugin
<form>
<input name="abc:quantity" value="1">
<input name="abc:variant" value="blue">
<input name="xyz:quantity" value="2">
<input name="foo:quantity" value="">
<button>Submit</button>
</form>
thanks for any suggestions