I have this array for doctrine to process many to many form and save it to db but my code is not working because only one instance of object is created and then rewritten when iterating through the array:
$i = '1';
foreach ($myarray as $key => $value) {
foreach ($value as $key2 => $value2) {
$addressObject = new \Entities\Clientaddress();
foreach ($value2 as $key3 => $value3) {
$addressObject ->$key3 = $value3;
$account->getAddresses()->add($addressObject);
$this->em->persist($addressObject );
$i = $i + '1';
}}}
If my approach is wrong what is the correct approach to create an object without defining it explicitly?
create an array of those objects: