Google Answers Logo
View Question
 
Q: PHP list command problem ( No Answer,   3 Comments )
Question  
Subject: PHP list command problem
Category: Computers > Programming
Asked by: document123-ga
List Price: $5.00
Posted: 19 Jan 2005 06:09 PST
Expires: 20 Jan 2005 02:43 PST
Question ID: 459785
Is it possible to use the value of a variable as the first parameter
to a list() command?

I'm trying the following with no success - I did have the variables
hardcoded in the list command - but I'd like to be able to make this
variable too if possible - can it be done simply? The only way I can
think of is creating the php script on the fly and running that, which
I'd rather not do?

<?php

// explode string into a structured record

$temp = '$title,
$first_name,
$surname,
$address_line1,
$address_line2,
$address_line3,
$address_line4,
$address_line5,
$postcode';

echo $temp;

list(

//define record structure

${$temp}

) = explode($file_delimiter,$buffer);

echo $title;
?>

Clarification of Question by document123-ga on 19 Jan 2005 09:36 PST
Vladimir,

Perfect. Thank you very much.

That had me stumped all afternoon. Are you a researcher - if so, post
this as your answer.

Clarification of Question by document123-ga on 20 Jan 2005 02:43 PST
Vladimir

I mailed GA support today saying what a great job you'd done.

Thanks very much for your help - no doubt I may have other things to
ask you in future....
Answer  
There is no answer at this time.

Comments  
Subject: Re: PHP list command problem
From: vladimir-ga on 19 Jan 2005 06:24 PST
 
You can use the eval() function to execute code that was constructed dynamically.

http://www.php.net/manual/en/function.eval.php

Vladimir
Subject: Re: PHP list command problem
From: vladimir-ga on 19 Jan 2005 06:27 PST
 
For example this should do the trick:

$temp = '$title,
$first_name,
$surname,
$address_line1,
$address_line2,
$address_line3,
$address_line4,
$address_line5,
$postcode';

eval('list('.$temp.') = explode($file_delimiter,$buffer);');


Vladimir
Subject: Re: PHP list command problem
From: vladimir-ga on 19 Jan 2005 13:26 PST
 
I'm not a researcher. If you want to help me become one, you can
e-mail answers-support@google.com saying that vladimir-ga helped you
and you think he would make a good researcher. :)

Vladimir

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy