RE: [PHP] A simple problem!

From: Date: Tue, 24 Apr 2001 18:18:32 +0000
Subject: RE: [PHP] A simple problem!
Groups: php.general 
Request: Send a blank email to php-general+get-50139@lists.php.net to get a copy of this message
Since $colour is assigned outside the function, it is in the global scope. Add the line "global $colour;" to the function to use $colour in the function's local scope. Kirk > -----Original Message----- > From: Subodh Gupta [mailto:subodhkgupta@satyam.net.in] > Sent: Tuesday, April 24, 2001 11:54 AM > To: PHP General > Subject: [PHP] A simple problem! > > > Can You figure out the mistake here...?? > > In the following code... In the function print_entry which I > am calling in some other file, I want each entry to printed > in a different colour. > > $colour = > array("808080","800000","FF00FF","0000FF","008080"); > $colouroffset=0; > > > function print_entry($row,$preserve="") > { > > // walk through any arguments passed in after the first two > $numargs = func_num_args(); > for ($i = 2; $i < $numargs; $i++) > { > $field = func_get_arg($i); > > // This will transform a label string to a valid database > // field name - e.g., "Last Name" becomes "last_name" > $dbfield = str_replace(" ", "_", strtolower($field)); > > $dbvalue = cleanup_text($row[$dbfield],$preserve); > $name = ucwords($field); > > print <<<EOQ > <tr>\n > <td valign=top align=right><b><font > color="#$colour[$colouroffset]">$name:</font></b></td>\n // > The problem is here.. the value of $colour[$colouroffset] is > not <td valign=top align=left><font > color="#$colour[$colouroffset]">$dbvalue</font></td>\n > // getting substituted. Can you tell me why?? > </tr>\n\n > EOQ; > } > > $colouroffset++; > } > > Subodh Gupta > I have learned, Joy is not in things, it is in us. > You will ultimately be known by what you give and not what you get. > >

« previous php.general (#50139) next »