- ucwords: documentation ( source)
- str_replace: documentation ( source)
- json_encode: documentation ( source)
<?php
$input = [
"1_apartment_bldgs"=>["geraldine", "jai_sai"],
"2_housings"=>["housing_prototype", "bla"]
];
$output = [];
foreach ($input as $key => $arr) {
$arr2 = [];
foreach ($arr as $p) {
$arr2[$p] = ['project' => ucwords(str_replace('_', ' ', $p))];
}
$output[$key] = $arr2;
}
echo json_encode($output, JSON_PRETTY_PRINT);