So I'm working on a problem where I need to convert an array of values into a string so that it can be displayed for an excel document. But I keep on getting an "Array to string conversion" error when I try to run the export. The code is
$counties = "";
if(isset($forms->form_info['county'])){
for($i = 0; $i < count($forms->form_info['county']); $i++){
if(is_int($i / 10) && $i != 0){
$counties .= $forms->form_info['county'][$i] . ",
";
} elseif($i == (count($forms->form_info['county']) - 1)) {
// Keep getting the error on the line below
$counties .= $forms->form_info['county'][$i] . " ";
} else {
$counties .= $forms->form_info['county'][$i] . ", ";
}
}
}
I've done a dd of a gettype on counties as well as the form element I'm trying to use, and both appeared as strings, so I'm lost on where the supposed array that's being converted is. I've tried making $form->form_info['county'][$i] into its own variable and concatenating it to the counties variable but received the same issue.
The result of dd($forms->form_info['county'][$i]); is
"Bernalillo County"
The result of dd($forms->form_info['county']); is
array:1 [▼
0 => "Bernalillo County"
]
The result of a dd(var_dump($forms->form_info['county'][$i])); is
string(17) "Bernalillo County"
null
And here is the direct screenshot of the issue