I have the code below. I am trying to loop through an array within a string and return the results to be a sub part of the string.
$household = '{
"data": {
"attributes": {
"name":"'.rgar( $entry, '1.6' ).'"
},
"relationships": {
"people":{
"data":[
'.
foreach ($family_ids[] as $fam_member){
return '{"type":"Person","id":"'.$fam_member.'"}';
}.'
]
},
"primary_contact":{
"data":{"type":"Person","id":"1"}
}
}
}
}';
echo($household);
My expected results would be along the lines of this
'{
"data": {
"attributes": {
"name":"'.rgar( $entry, '1.6' ).'"
},
"relationships": {
"people":{
"data":[
{"type":"Person","id":"2"},
{"type":"Person","id":"3"},
{"type":"Person","id":"4"}, //note the commas
{"type":"Person","id":"5"}
]
},
"primary_contact":{
"data":{"type":"Person","id":"1"}
}
}
}
}';
I believe my issue is related to my quotation marks to break in and out of the string. However I am also not sure how to address to comma being removed for the last result.