note 94868 rejected from control-structures.foreach by thiago
| From: | thiago@php.net | Date: | Mon, 30 Nov 2009 12:03:12 +0000 |
| Subject: | note 94868 rejected from control-structures.foreach by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163402@lists.php.net to get a copy of this message | ||
Note Submitter: rnfbr1 at hotmail dot com
----
Strange behavior , an array is passed by value to a function,
the array is intact, but if i put it through a foreach to access its elements , the array turns
into a string.
this is $datos contents
Array ( [id] => 25 [estudiantes_id] => 14 [matriculas_id] => 53 [nombre] => JOHN
DOE[cursos_id] => 48 [anio] => 2009 [mes] => 11 [dia] => 28 [horadesde] => 06:00:00
[horahasta] => 08:00:00 ) Array ( [id] => 23 [estudiantes_id] => 8 [matriculas_id] => 52
[nombre] => JANE DOE [cursos_id] => 62 [anio] => 2009 [mes] => 11 [dia] => 28
[horadesde] => 11:00:00 [horahasta] => 12:00:00 ) Array ( [id] => 22 [estudiantes_id] =>
19 [matriculas_id] => 57 [nombre] => HOMER SIMPSON [cursos_id] => 63 [anio] => 2009
[mes] => 11 [dia] => 16 [horadesde] => 07:00:00 [horahasta] => 13:00:00 )
This is the function
function FancyTable($header,$datos,$longitudArr)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=$longitudArr;
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
//this foreach statement transforms array to string!!!!!
foreach($datos as $datos1){
print_r($datos1); //this outputs string
}
the output from the foreach statement is
251453JOHNDOE482009
This is crazy, how i am supposed to retrieve an array field
if everything is joined together , no spaces , no delimiter.
Is this a bug??? I use PHP 5.2.5