Bennovations Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

Populating an array inside of a for loop using PHP

Views: 393
Votes: 0
Posted: 03 Jun, 2009
by: Patridge B.
Updated: 03 Jun, 2009
by: Patridge B.
Populating an array from inside a loop is very easy:

file: x.php
//====================================================
<?php

$i=10;

for ($x=0;$x<=$i;$x++) {
$testarray[]=$x;
}

foreach ($testarray as $value) {
echo "$value<BR>";
}
?>
//====================================================

#>php x.php
0
1
2
3
4
5
6
7
8
9
10
#>
Others in this Category
document Nested Variable assignments within PHP - Calling a variable with a variable inside a FOR loop
document Multi-dimensional PHP Arrays



RSS