0

in PHP i need to use this

$pdf->SetXY(56, 100);

but now i need the parameters in variables

$paramxy= "56, 100";

PHP doesn't seem to like me writing

$pdf->SetXY($paramxy);

it doesn't evaluate "$paramxw" as two separate values..

of course the easy solution would be :

$param[x]= 56; 
$param[y]= 100;
$pdf->SetXY($param[x],$param[y]);

but i'd like it to be shorter and more readable, because I need lots of these two lines..

is there a "parse" like function that I could use, for example like that ?

$pdf_paramxy= "56, 100";
$pdf->SetXY(parse($paramxy));
1
  • This smells dangerouly like eval... Commented Nov 8, 2013 at 12:59

2 Answers 2

1

Native? Not. But you can create your own:

$paramxy= "56, 100";
$params = explode(",", $paramxy);

Then, according to this, you can:

call_user_func_array(array($pdf, "SetXY"), $params);

If values of the array being a string is a problem, you can parse it by each value:

foreach($params as $key => $value)
{
    $params[$key] = (int)$value;
}

call_user_func_array(array($pdf, "SetXY"), $params);

Didn't tested it. Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

you can't set a value for a variable in the following manner $pdf_nomenfant= "56, 100"; To achieve your target you have two ways.

  1. create two parameters with different values like $param1 = "56"; and $param2 = "100";

and the other way is to use an array for this task as in the following:

  1. '$paramxy= array ("56, 100"); $pdf->SetXY(parse($paramxy));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.