Create variables programmatically [duplicate]

1

Is it possible to create variables programmatically?

Example ( this example does not work, it's just to understand the idea ):

I want to create the variables: $var0 , $var1 , $var2 , $var3 and print your name and value.

$qtdVariaveis = 5;
$prefixo = 'var';
$valorPadrao = 10;

for ($c = 0; $c < 5; $c++) {

    echo $prefixo . $c = $valorPadrao;
}

Desired output:

$var0 = 10
$var1 = 10
$var2 = 10
$var3 = 10
    
asked by anonymous 13.04.2018 / 18:17

1 answer

3

There is but you should not do it, you have no reason to do this.

Use an array and be happy. Be it with a sequential numeric index, be an associative with the whole name.

    
13.04.2018 / 18:21