SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding variable to another variable name

    Hi chaps

    I've got a variable called $question

    I'm running a "for" loop and i want $i to be added to the $question variable name above.

    So for example

    if $i = 3

    I want to write an expression which says $question3

    I know how to do this in flash, but am perplexed in php.

    Any help would be greatly appreciated.

  2. #2
    SitePoint Addict rokc's Avatar
    Join Date
    Oct 2004
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $question.$i

  3. #3
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers mi dear :-)

  4. #4
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i've tried this and this does not work

    what it does is concatenate the contents of $question and $i
    so if $question is 30 and $i is 1
    the result is 301

    I want $question1

    any other ideas?

    Many thanks!

  5. #5
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:
    PHP Code:
    for($i=0;$i<=10;$i++)
    {
    $newvar 'question'.$i;
    echo $
    $newvar;

    This should work


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •