Ggggggg
<?php
/* ejemplo 1 */
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
/* ejemplo 2 */
for ($i = 1; ; $i++) {
if ($i > 10) {
break;
} echo $i;
}
/* ejemplo 3 */
$i = 1;
for (; ; ) {
if ($i > 10) {
break;
}
echo $i;
$i++;
}
/* ejemplo 4 */
for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);?>
Ejemplo de while
<?php
/* ejemplo 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* el valor presentado sería
$i antes del incremento (post-incremento) */
}
/* ejemplo 2 */
$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;
?>
-------------------------------------------------
<?php
$finaldir = 'download';$finished = false; // we're not finished yet (we just started)
while ( ! $finished ): // while not finished
$rn = rand(); // random number $outfile = $finaldir.'/'.$rn.'.gif'; // output file name
if ( ! file_exists($outfile) ): // if file DOES NOT exist...
$finished = true; // ...we are finished
endif;endwhile; // (if not finished, re-start WHILE loop)
?>
-------------------------------------------------
<?php
$q1 = 'some query on a set of tables'; $q2 = 'similar query on a another set of tables';
if ( ($r1=mysql_query($q1)) && ($r2=mysql_query($q2)) ) {
while (($row=mysql_fetch_assoc($r1))||($row=mysql_fetch_assoc($r2))) { /* do something with $row coming from $r1 and $r2 */
}
}
?>
<?PHP
$i=0;
while($i < count($one)) {
while($a = each($two)) {
echo $a[1]." -".$one[$i].", ";
}
$i++;
}
?>
Ejemplo de if
<?php
if ($a > $b) {
echo "a es mayor que b";
}
?>
-----------------------
<?php...
Regístrate para leer el documento completo.