note 94868 added to control-structures.foreach
| From: | rnfbr1 at hotmail dot com | Date: | Mon, 30 Nov 2009 07:23:32 +0000 |
| Subject: | note 94868 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163390@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 190.155.54.26
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/94868
Del: integrated -- https://master.php.net/note/delete/94868/integrated
Del: useless -- https://master.php.net/note/delete/94868/useless
Del: bad code -- https://master.php.net/note/delete/94868/bad+code
Del: spam -- https://master.php.net/note/delete/94868/spam
Del: non-english -- https://master.php.net/note/delete/94868/non-english
Del: in docs -- https://master.php.net/note/delete/94868/in+docs
Del: other reasons-- https://master.php.net/note/delete/94868
Reject -- https://master.php.net/note/reject/94868
Search -- https://master.php.net/manage/user-notes.php