I'm trying to dynamically add items to an array based on the number given by a user. I reference a template that has an array of object data inside of it. I get that Object by its SectionName and then through the for loop I'm trying to dynamically Change the SectionId and SectionName but Im getting the same one in there no mater what number is entered above 1.
$decodedTemplateArray = array();
// decoded json template to array
$decodedTemplateArray = json_decode($templateJsonData[0]->UnitTemplateForm);
// find location of bedroom section in array
$bedroomSectionLocation = array_search("Bedroom", array_column($decodedTemplateArray, 'SectionName'));
// set bedroom section to be created
$bedroomSectionObj = $decodedTemplateArray[$bedroomSectionLocation];
// remove bedroom from Template
unset($decodedTemplateArray[$bedroomSectionLocation]);
// insert 3/4/5
for ($x = 1; $x <= $bedroomCount; $x++) {
$secGuid = self::generateGuid();
$bedroomSectionObj->SectionId = $secGuid;
$bedroomSectionObj->SectionName = "Bedroom " . $x;
array_push( $decodedTemplateArray, $bedroomSectionObj);
}
Array Result:
7: {SectionId: "915E3E49-619F-190E-BFD4-7892871B1530", SectionName: "Bedroom 2", SectionDisplaySequence: 3, SectionItems: Array(9)}
8: {SectionId: "915E3E49-619F-190E-BFD4-7892871B1530", SectionName: "Bedroom 2", SectionDisplaySequence: 3, SectionItems: Array(9)}