Simple PHP algorithm questions (with expansion), PHP algorithm questions expansion
Simple PHP algorithm questions (to be improved...)
Only print 0
The specific number is determined by the input parameter n
If n=5, print 00000
Print n zeros based on n value
Print a line 0101010101010101010101
The specific number is determined by the input parameter n
For example, test.php?n=3 prints 010
Print 010101... based on n value
Achieve 1 00 111 0000 11111
for if implementation
![](http://www.bkjia.com/uploads/allimg/150712/16393522N-0.gif)
php
for (
$i = 0;
$i < 10;
$i ) {
for (
$j = 0;
$j <=
$i;
$j ) {
if (
$i % 2 == 0
) {
echo '0'
;
} else {
echo '1'
;
}
}
echo '
'
;
}
?>
implementation of for&if statement
for switch implementation
![](http://www.bkjia.com/uploads/allimg/150712/16393522N-0.gif)
php
for (
$i = 0;
$i < 10;
$i ) {
for (
$j = 0;
$j <=
$i;
$j ) {
switch (
$j % 2
) {
case '0':
echo "0"
;
break;
case '1':
echo "1"
;
break;
}
}
echo '
'
;
}
?>
for&switch statement implementation
while if implementation
While switch implementation
![](http://www.bkjia.com/uploads/allimg/150712/16393522N-0.gif)
php
$i = 0
;
while (
$i < 10
) {
$j = 0
;
while (
$j <=
$i) {
switch (
$i % 2
) {
case 0:
echo '0'
;
break;
case 1:
echo '1'
;
break;
}
$j ;
}
echo '
'
;
$i ;
}
?>
While&switch statement implementation
Realize 0 01 010 0101……
Realize 0 01 012 0123 3210 210 10 0
Be a calculator
For example, test.php?a=1&b=2&operator=jia output 3
For example, test.php?a=5&b=2&operator=jian outputs 3
For example, test.php?a=2&b=5&operator=cheng outputs 10
For example, test.php?a=6&b=3&operator=chu output 2
Four-digit calculation function that can handle addition, subtraction, multiplication and division
Advanced:
Number of daffodils
Bubble sorting method
http://www.bkjia.com/PHPjc/1030384.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1030384.htmlTechArticleSimple PHP algorithm questions (with expansion), PHP algorithm questions expanded simple PHP algorithm questions (to be improved) only Print 0. The specific number is determined by the input parameter n. For example, if n=5, print 00000. Print according to the n value...