Re: Making variables with an iteration?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 06 December 2004 23:13, Robert Sossomon wrote:
> <SNIP>
>
> Parse error: parse error, expecting `';''

You should always give the full error message which would include the line 
number. Furthermore you should always point out which line of your code is 
the line number in question.

> coded:
> <?php
> for ($j=1, $j<5, $j++)

; not ,

> {
>   $choices.$j= $_POST['choice'.$i];
>   echo $choices.$j;
> }
> ?>

    $varname = "choices$j";
    $$varname = $_POST['choice'.$j]; // or $_POST["choice$j"]
    echo ${"choices$j"}, NL;

Please note that using variable variables isn't recommended. Using arrays 
makes the code much clearer. I believe that you 'chose' to use variable 
variables because you had to do some processing in Javascript, read

manual > PHP and HTML

to see how to handle PHP's array naming conventions under Javascript.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
<Hydroxide> knightbrd: from knightbrd.brain import * :)
<knghtbrd> Oh gods if it were that easy ..
<knghtbrd> from carmack.brain import OpenGL
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux