Very difficult to explain in a sentence sorry so here is example.
I have this array:
$setParams = [
'repeat_delay' => [23, 1],
'repeat_type' => ['Hour', 'Day'],
];
that I want to turn into this
$wanted = [
[
'repeat_delay' => 23,
'repeat_type' => 'Hour'
],
[
'repeat_delay' => 1,
'repeat_type' => 'Day'
]
];
I have it working but wanting to know if there is a cleaner way, or even another way.
$newArray = [];
$setKeys = array_keys($setParams);
$setValues = array_values($setParams);
$isSetValueArray = array_filter($setValues,
static function ($setValue) {
return is_array($setValue);
});
if (!empty($isSetValueArray)) {
foreach ($setKeys as $keyCount => $key) {
foreach ($setValues as $valueCount => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
if ($keyCount === $valueCount) {
$newArray[$k][$key] = $v;
}
}
}
}
}
}
Some more information to help others. I am sorry I didn't provide sooner as I know context is everything.
Here is a link to my snippet with more info and complete example.