|
4 Aug 2003, 14:42
|
#1
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Returning PHP values from functions.
I've not slept for days, so my brain is rotting. Anything wrong with this? I can't get $img back from the function...
Code:
function doImg ($title, $level, $img)
{
if ($level == 4)
{
$img = $title.'-raog.gif';
}
elseif ($level == 3)
{
$img = $title.'-rao.gif';
}
elseif ($level == 2)
{
$img = $title.'-ra.gif';
}
else
{
$img = $title.'-r.gif';
}
return $img;
}
doImg('test', 1, $img);
echo '<img src=img/'.$img.'>';
Cheers,
M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Aug 2003, 14:46
|
#2
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Either use
Code:
$img=doImg('test', 1, $img);
(preferred)
Or pass by reference to get the semantics you seem to want:
Code:
function doImg ($title, $level, &$img)
__________________
#linux
|
|
|
4 Aug 2003, 14:49
|
#3
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Quote:
Originally posted by queball
Either use
Code:
$img=doImg('test', 1, $img);
(preferred)[/code]
|
Goddamnitalltohell! Like I said, my brain is asleep today, I'm on auto.
Quote:
Originally posted by queball
Or pass by reference to get the semantics you seem to want:
Code:
function doImg ($title, $level, &$img)
|
Passing by reference in PHP is something I avoid wherever possible
Ta,
M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Aug 2003, 14:58
|
#4
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Many thanks, my entirely pointless and self-indulgent thingie is working now
You think this is excessive? It uses a MySQL DB... surely that's entirely reasonable?
M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Aug 2003, 15:09
|
#5
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Very "Kevin Warwick"
|
|
|
4 Aug 2003, 15:14
|
#6
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Quote:
Originally posted by queball
Very "Kevin Warwick"
|
Who?
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Aug 2003, 16:36
|
#8
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
I've never seen this kinda thing before... assumed I was being original
M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Aug 2003, 16:47
|
#9
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by Mong
I've never seen this kinda thing before... assumed I was being original
|
Well, "happy" or "unhappy" icons.
MySQL certainly isn't overkill. I can't think of a better protocol for transferring the data from your cybernetic implants to the web.
|
|
|
13 Aug 2003, 10:37
|
#10
|
Ensign
Join Date: Apr 2000
Location: An intricate fantasy world.
Posts: 166
|
Code:
function doImg ( $title, $level )
{
switch ( $level ) {
case 4:
$img = $title.'-raog.gif';
break;
case 3:
$img = $title.'-rao.gif';
break;
case 2:
$img = $title.'-ra.gif';
break;
default:
$img = $title.'-r.gif';
}
return $img;
}
$img = doImg ( 'test', 1 );
echo '<img src="img/'.$img.'">';
Is probably better...
Last edited by Coffee; 14 Aug 2003 at 10:15.
|
|
|
|
All times are GMT +1. The time now is 09:20.
| |