Forum Moderators: coopster

Message Too Old, No Replies

Using a string as a part of a function

         

yoavr

5:02 am on Feb 1, 2010 (gmt 0)

10+ Year Member



How can I use a string as a part of a function?
I'll explain - I have:
$a = "0,0,0,100";
and I want to put it in the coords part of the imageline() function: (a GD function)
imageline($image,$x1,$y1,$x2,$y2,$color);

I want that "$x1,$y1,$x2,$y2" will be "0,0,0,100".
Something like: imageline($image,$a,$color);

Hope I explained my question clearly. :)

Readie

5:43 am on Feb 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could declare $a as an array, like so:

$a = array($x1,$y1,$x2,$y2);

and then when you call it in your function you'll need to say "$a[0], $a[1], $a[2], $a[3]" for each respective value in the array.

I think that's what you're asking anyway..?

yoavr

6:30 am on Feb 1, 2010 (gmt 0)

10+ Year Member



No, it's not good.. I need the "x1,y1,x2,y2" in one variable (for this case "$a[0],$a[1]" and "$a,$b" is the same) because the string in this var comes from a DB field.

rocknbil

5:53 pm on Feb 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



because the string in this var comes from a DB field.

Something like this?


imageline($image,$imgstr,$color);
function imageline($img,$coords,$bg) {
$coords = explode (',',$coords);
// etc.
}

You're of course better off not storing it as a string in the first place, but as individual tinyint fields or a relational table, this is one of many problems with that approach.