SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    Location
    usa
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    for loop and dynamic variables? PHP bug?

    ok i've run into a little roadblock here .. I'm trying to pull out a variable and make a new variable out of it ($f4 for example). the following lines will work in my code:

    Code:
    $var="f".$num[0]; $$var = 1; 
    $var="f".$num[1]; $$var = 1; 
    $var="f".$num[2]; $$var = 1; 
    $var="f".$num[3]; $$var = 1;
    but since i expect [i] to change depending on how many checkboxes the user clicks, I want to put it in a for loop but it just won't work! is there a bug in PHP?

    Code:
    for ($i=0; $i < 10; $i++) 
    	{ 
    		$var="f".$num[i]; 
    		$$var = 1;  
    	}

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $num[$i] not $num[i]

    if that was just a typo - try evaling

    for()
    {
    eval("\$f" .$i. " = 1");
    }
    teckis - that's news to me.


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
  •