I have a function that is returning an array from a function do not know the syntax to use it correctly. I am returning an array of colors to use at various places.
Here is the function:
[syntax=php]ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini)[/syntax]
Here is how I am using it without returning an array (single value)
[syntax=php]<Font Color='".ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini)."'>[/syntax]
I want to return an array with fontcolor just be one of the returned values so I have tried ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini)['fntCol'] but am getting a parse error (unepected "[").
How to use an Array returned from a Function
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Code: Select all
ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini)If you want to change the information returned by a function you have to edit the function - not the call. What is the code for ColorShotVal()?
You can probably save the returned value from the function as a variable, if the value is indeed returned and not just echoed from the function.
Try:
Code: Select all
$colorї'fntCol'] = ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini);http://www.php.net/manual/en/functions.php
http://www.php.net/manual/en/functions. ... values.php
Mac
Here's a portion the Function:
I have multiple lines that are posted from a record set with a loop. Here are two.
Code: Select all
FUNCTION ColorShotVal($Shot, $Val, $Flag, $Vini){
Switch ($Shot){
CASE 'Ltch';
$aCol = array('bgColor' => '#EFEFEF' ,'fontColor' => '#000000' );
Return $aCol;
break;Code: Select all
<TD Class='datacol'><Font Color='".ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini)."'>$AvgLtch </Font></TD>
<TD Class='datacol'><Font Color='".ColorShotVal('Bffr',$AvgBffr, $AvgFlag, $AvgVini)."'>$AvgBffr </Font></TD>Since the function returns an array, I think you need to have a variable get the function's return value.
What about something like this:
And then use the 'fontColor' keys in the arrays (I haven't tested this):
What about something like this:
Code: Select all
$ltch_color = ColorShotVal('Ltch',$AvgLtch, $AvgFlag, $AvgVini);
$bffr_color = ColorShotVal('Bffr',$AvgBffr, $AvgFlag, $AvgVini);Code: Select all
echo "<TD Class='datacol'><Font Color='".$ltch_colorї'fontColor']."'>$AvgLtch </Font></TD>";
echo "<TD Class='datacol'><Font Color='".$bffr_colorї'fontColor']."'>$AvgBffr </Font></TD>";