'PHP literally outputting the word 'Array' instead of the values in said array
Before you immediately close the question, please read first. I know about var_dump(), print_r(), echo etc. It just doesn't seem to work in my particular use-case, or I'm unsure how exactly to implement them in my exact situation.
After updating to the integrated PDO data abstraction layer, its giving us our data back formatted a bit differently.
One of our forms would output a list of arrays converted to strings. Below is a snippet:
$this->output .= "<option id='".$option_name."' value='".$values[$i]."'".$selected.">".$options[$i]."</option>\n";
Each $options[$i] is an array that contained material id and description. So it would look something like this when output properly:
- Red Material 1234
- Blue Material 2235
- Green Material 3236
- ....etc...
What the array looks like for each would be: Array ([description] => Red Material [materialid] => 1234)
Now it just outputs:
- Array
- Array
- Array...
How can I just convert $options[$i] to a string before feeding it to this output field?
Some assistance would be appreciated. I feel like I'm getting caught up on something that should be trivial.
Solution 1:[1]
$options[$i] is an array, and when you convert an array to a string you get the string Array.
You want to get the elements of the array:
$this->output .= "<option id='{$option_name}' value='{$values[$i]}' $selected>{$options[$i]['description']} {$options[$i]['materialid']}</option>\n";
Using string substitution instead of concatenation makes the code easier to read, and often avoids quoting problems.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barmar |
