Jump to content

syntax problem


felito

Recommended Posts

hi

 

what is the problem of this php?

 

$i=0;
while ($sql -> fetch()) {
		 $num.$i++ = $form[$val]; // error here
		 echo ($num0);
	}

 

i want something like:

 

$num0 =$form[$val];
$num1 =$form[$val];
$num2 =$form[$val];
...

 

thanks

Link to comment
Share on other sites

I doubt seriously this is the best way to handle whatever it is that you are trying to do, however it can be accomplished.

 

$i=0;
while ($sql -> fetch()) {
                         $name = 'num' . $i++;
		 $$name = $form[$val]; 			 
}

// now you'll have variables $num0... x

for ($x = 0; $x   echo '$num'.$x . ' = ' .  ${'num'.$x} . '
';
}

 

 

Link to comment
Share on other sites

Don't ever use variable variables unless you're absolutely certain there's no other way to go about doing things.  If you ever have variables with sequential numbers at the end, you've done it wrong.  The Array construct is perfect for what you're trying to do.

 

-Dan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.