I have done some searching on Stackoverflow already on this topic, however as far as I can tell, I am not treating an array as a string ?
The message I am getting is :
Array to string conversion in X on line 42
Line 42 of my code is the opening of a foreach
loop :
foreach ($collection as $element) {
Variable $collection
is a caching iterator that is based on database output:
$collection=new \CachingIterator(new \ArrayIterator($this->dbData));
If I print_r()
on $this->dbData
, I certainly get an array:
Array
(
[0] => Array
(
[c_id] => A
)
[1] => Array
(
[c_id] => B
)
So, in summary:
- We have a confirmed output of an array
- We know that
ArrayIterator()
expects anarray
as argument - We know that
CachingIterator()
expects anIterator
as argument - We know that
foreach()
can loop over anIterator
TL;DR I am really not sure what I am treating as string here ?
EDIT TO ADD....
Even if I greatly simplify my code, I can still reproduce:
<?php
error_reporting (E_ALL | E_STRICT);
ini_set ('display_errors', 1);
$arrX=array(array("c_id"=>"A"),array("c_id"=>"B"));
$collection=new \CachingIterator(new \ArrayIterator($arrX));
foreach($collection as $element) {
echo $element["c_id"].PHP_EOL;
}
Notice: Array to string conversion in /Users/bp/tmp/test.php on line 6
A
Notice: Array to string conversion in /Users/bp/tmp/test.php on line 6
B