Hello friends, today I have a question about how to extract and save a list from an array.
This is the code I am using:
$datos = Array ( [0] => Array ( [0] =>
Array ( [0] => _22938513 [1] => _45984789 [2] => _45966879 [3] => _46048227 [4] => _26767583 [5] => _45137827 [6] => _41538617 [7] => _45860863 [8] => _45543708 [9] => _41792665 [10] => _28212331 [11] => _44209003 [12] => _23660986 [13] => _45567819 [14] => _45539598 [15] => _46004147 [16] => _45930599 [17] => _45523079 [18] => _46041147 [19] => _33272309 [20] => _45935183 [21] => _45979315 [22] => _10132780 [23] => _28618737 [24] => _34169477 [25] => _37682775 [26] => _45486965 [27] => _36919699 [28] => _36606257 [29] => _45506299 [30] => _45937685 [31] => _40691491 [32] => _45993339 [33] => _45870235 [34] => _45941369 [35] => _19510939 [36] => _45917853 [37] => _45652307 [38] => _45345349 [39] => _45992177 [40] => _41820795 [41] => _45579257 [42] => _26216871 [43] => _45668761 [44] => _45541170 [45] => _45919709 [46] => _45553620 [47] => _45585261 [48] => _46033219 [49] => _45811439 ) );
$contenido="";
foreach($datos as $row){
$contenido .= $row.PHP_EOL;
}
Echo $contenido;
The result I want to achieve is: _22938513 _45984789 _45966879
This is the error message. "Notice: Array to string conversion"
I hope some idea why with this type of array the foreach method does not work and what is the best way. and apologies if it is not well written. is to use the cell phone.
The problem is how you access the array where the data is, since you have an array of one element that contains another array of one element and the latter contains 50 elements with your data, which is where the loop path should affect.
In php format your array would be equivalent to this example:
And with the foreach we would go through the data array in this case, accessing the first element of the two arrays that contain it.
A generic solution would be through a recursive function, which checks if a given element is an array or not . We can do it both in depth and in height... in the absence of more data, and since it is simpler, I have chosen to do it in depth:
Departure:
If the array is always the same, I see no reason to complicate your life. It could be fixed with a single line using
implode
:Departure:
That's all folks!