for($y=1; $y<=$height; $y++){
$l = $height-$y;
$r = $y*2-1;
echo $y."\t".$l."\t". $r."\t".str_repeat(' ', $l ).str_repeat('*', $r )."\n";
}
А откуда ты знаешь, что там внутри драйвера? Там может быть что угодно. И зависеть от СУБД и соединения.раньше копай... откуда взялся этот набор объектов? while
ну уже добьем эти цифорки... важно же научиться а не задачу решить... денег все одно не заплатят... но можешь сказать, я решил ее в 2 цикла! и считаю это достаточным...в 2 цикла и с ошибками уже получилось...(но нужно в 1 да)
Нужен он, но не для подобных задач.Absinthe
ну почему нельзя просто сказать, "да порою нужен for"?
$height = 4;
for($y=1; $y<=$height; $y++){
$l = $height-$y;
$r = $y*2-1;
echo $y."\t".$l."\t". $r."\t".str_repeat(' ', $l ).str_repeat('*', $r )."\n";
}
$height = 4;
for($y=3; $y<=$height; $y--){
$l = $height-$y;
$r = $y*2-1;
echo $y."\t".$l."\t". $r."\t".str_repeat(' ', $l ).str_repeat('*', $r )."\n";
}
1 3 1 *
2 2 3 ***
3 1 5 *****
4 0 7 *******
3 1 5 *****
2 2 3 ***
1 3 1 *
<!--error--><br />
<b>Warning</b>: str_repeat() [<a href='function.str-repeat'>function.str-repeat</a>]: Second argument has to be greater than or equal to 0 in <b>S:\home\localhost\www\fo\forOMG.php</b> on line <b>14</b><br />
<script language=JavaScript src='/denwer/errors/phperror_js.php'></script>0 4 -1
<!--error--><br />
<b>Warning</b>: str_repeat() [<a href='function.str-repeat'>function.str-repeat</a>]: Second argument has to be greater than or equal to 0 in <b>S:\home\localhost\www\fo\forOMG.php</b> on line <b>14</b><br />
<script language=JavaScript src='/denwer/errors/phperror_js.php'></script>-1 5 -3
<!--error--><br />
$height = 4;
for($y=1; $y<$height; $y++){
$l = $height-$y;
$r = $y*2-1;
echo $y."\t".$l."\t". $r."\t".str_repeat(' ', $l ).str_repeat('*', $r )."\n";
}
$height = 0;
for($y=2; $y>$height; $y=$y--){
$l = $height+$y;
$r = $y*2-1;
echo $y."\t".$l."\t". $r."\t".str_repeat(' ', $l ).str_repeat('*', $r )."\n";
1 3 1 *
2 2 3 ***
3 1 5 *****
2 2 3 ***
1 1 1 *
)PHP:<?php for($x=1; $x<=4; $x++) { for($y=1; $y<=$x; $y++) { echo "*"; } echo "\n"; } ?>
for($x=1; $x<=4; ++$x) {
for($y=1; $y<=$x; ++$y) {
echo "*";
}
echo "\n";
}
нет, php != CТак будет быстрее
Простите а разве ядро php написанно не на С? Собственно нативные функцции в таком случаее работают как на Снет, php != C
$tstart = microtime(true);
for($x=1; $x<=10000000; $x++) {
}
$tstop = microtime(true);
print $tstop - $tstart;
print" > ";
$tstart1 = microtime(true);
for($x=1; $x<=10000000; ++$x) {
}
$tstop1 = microtime(true);
print $tstop1 - $tstart1;