I have an array wich is structured like this
- foo = stuff we don't care for this example
- foo1_value
- foo1_label
- foo1_unit
- foo2_value
- foo3_label
- foo3_value
Can you figure out a fast way to make it look like that ?
- foo
- foo1
- value
- label
- unit
- foo2
- value
- foo3
- value
- label
I'm actually trying with something like this :
array_walk($array, function($val, $key) use(&$nice_array) {
$match = false;
preg_match("/_label|_value|_unit|_libelle/", $key, $match);
if (count($match)) {
list($name, $subName) = explode('_', $key);
$nice_array[$name][$subName] = $val;
} else {
$nice_array[$key] = $val;
}
});
echo '<pre>';
print_r($nice_array);
echo '</pre>';
This is working I'll just have to reflect on the foo_foo_label thing and it's all good