Sorry if this is too obvious but I’ve been too long on it and now I cannot think how to do it.
I have:
$objectPerson = new Person();
$objectPerson->setName($arrayName);
$objectPerson->setLastName($arrayLastName);
$arrayPerson = array();
$arrayPerson[] = $objectPerson;
$objectMainClass->setArrayPerson($arrayPerson);
$arrayName and $arrayLastName are coming from a $_REQUEST and have two elements each: John, Jean and Smith, Taylor
I will store $objectMainClass later in my database table that has this structure:
Id | Name | LastName
But the way the code is now, I’m storing John, Jean in the name field and Smith, Taylor in the last name field like that:
Id | Name | LastName
-------------------------------
1 | John, Jean | Smith, Taylor
What can I do to get:
Id | Name | LastName
--------------------
1 | John | Smith
2 | Jean | Taylor
??
I know I have to use a foreach in the code above but I’m so stuck that I cannot think on how to do it.
Thanks a lot
I had to fix some errors in the code, but this should work: