variables - Naming PHP object children in for loop -


i want this:

<?php echo $factuurgegevens->aantal.$i; ?> 

but doesn't work, how can handle this?

so have get:

<?php echo $factuurgegevens->aantal1; ?> <?php echo $factuurgegevens->aantal2; ?> <?php echo $factuurgegevens->aantal3; ?> <?php echo $factuurgegevens->aantal4; ?>  

you can use curly braces ({}) make dynamic variables:

$name = 'aantal'; for($i = 0 ; $i < 5 ; $i++)    echo $factuurgegevens->{$name . $i}; 

however should use array because made things this:

$factuurgegevens->aantal = array(); $factuurgegevens->aantal[1] = 'something'; $factuurgegevens->aantal[2] = 'something'; $factuurgegevens->aantal[3] = 'something'; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -