I have an array:
$errors = array(
"data.bedrooms[0].description"=> "Description cannot be blank",
"data.bedrooms[0].rentamount"=> "Rentamount cannot be blank",
"data.bedrooms[0].bondamount"=> "Bondamount cannot be blank",
"data.bedrooms[0].maxallowedoccupants"=> "Max allowed occupants cannot be blank",
"data.bedrooms[0].includedbills"=> "Included Bills cannot be blank",
"data.bedrooms[0].suitabilities"=> "Suitable for cannot be blank",
"data.bedrooms[0].area.value"=> "Area cannot be blank",
"data.bedrooms[1].description"=> "Description cannot be blank",
"data.bedrooms[1].rentamount"=> "Rentamount cannot be blank",
"data.bedrooms[1].bondamount"=> "Bondamount cannot be blank",
"data.bedrooms[1].maxallowedoccupants"=> "Max allowed occupants cannot be blank",
"data.bedrooms[1].includedbills"=> "Included Bills cannot be blank",
"data.bedrooms[1].suitabilities"=> "Suitable for cannot be blank",
"data.bedrooms[1].area.value"=> "Area cannot be blank"
);
I want to convert it into a two dimensional array which should look like :
$errorsarray = array( 0 => array(
'description'=>'Description cannot be blank',
'rentamount'=>'Rentamount cannot be blank',
'bondamount' => 'Bondamount cannot be blank'
),
1 => array(
'description'=>'Description cannot be blank',
'rentamount'=>'Rentamount cannot be blank',
'bondamount' => 'Bondamount cannot be blank'
)
);
How do I do that. I've tried many different solutions but I cannot get the desired result. Any Ideas?
EDIT: This is how far i've got:
$newArray = array();
foreach ($errors as $key => $value) {
$parts = substr($key, 13);
$property = substr($parts, 4);
$formnumber = substr($parts,1,1);
$newArray[$formnumber] = array($property => $value);
}
var_dump($newArray);exit;
maxallowedoccupantskey been missed?suitabilitieskey been missed?