Jump to content

Loop and assign value to variable


denoteone

Recommended Posts

I know if actionscript you can loop through and assign values to variables and just increment a number in the variable name like so.....  Is this possible in php

 


$result = clientTestimonial();
					$i = 0;
 					while($row = mysql_fetch_assoc($result)){

					$company_$i = $row['company'] ;
					$name_$i  =    $row['name'] ;
					$teaser_$i =  $row['teaser'] ;
					$i++
					}

Link to comment
https://forums.phpfreaks.com/topic/187661-loop-and-assign-value-to-variable/
Share on other sites

Generating a list of sequentially numbered variables to hold a set of same type data is never a good idea. Once you have created them, you need extra logic to keep track of them and iterate over the correct number of them.

 

Arrays should be used when you have a set of same type data, that's what array data structures are for.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.