Re: varibles defination

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

 



There are two ways of accomplishing what I think you're trying to acomplish.

These ways are known as the right way and the wrong way. 

the right way results in an array like

$func = array(0 => 0, 1 => 1, 2 => 2 ...)

The wrong way results in a set of variables like you described 

$func1 = 0
$func2 = 1
$func3 = 2
$func4 = 3
$func5 = 4

If you want to do it the wrong way, you can 

for($i = 1; $i < 5 ++$i){
  $varname = "func" . $i;
  $$varname = $i;
}

Personally I reckon you should do it the right way as Jim outlines.

On 8/2/05, Jim Moseby <JMoseby@xxxxxxxxxxxxxxxxx> wrote:
> > If I want to define and display a set of varibles, for example :
> > $func1 = 0
> > $func2 = 1
> > $func3 = 2
> > $func4 = 3
> > $func5 = 4
> >
> > How can we define and display the varibles by using for loop
> > function ?
> 
> <?php
> for ($x=0;$x<10;$x++){
>  $func[$x]=$x;
> }
> print_r($func);
> ?>
> 
> This uses an array, so, in this case, your variables would be referenced as
> $func[0]..$func[9].
> 
> JM
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
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