Print 0 only The specific number is determined by the input parameter n. If n = 5, 00000 is printed.
- $ N = $ _ GET ['n'];
- For ($ I = 0; $ I <$ n; $ I ++ ){
- Echo "0 ";
- }
- ?>
Print a row 0101010101010101010101 The specific number is determined by the input parameter n. Such as test. php? N = 3 print 010
- $ N = $ _ GET ['n'];
- For ($ I = 0; $ I <$ n; $ I ++ ){
- If ($ I % 2 = 0 ){
- Echo "0 ";
- } Else {
- Echo "1 ";
- }
- }
- ?>
1 00 111 0000 11111 For if implementation
-
- For ($ I = 0; $ I <10; $ I ++ ){
- For ($ j = 0; $ j <= $ I; $ j ++ ){
- If ($ I % 2 = 0 ){
- Echo '0 ';
- } Else {
- Echo '1 ';
- }
- }
- Echo'
';
- }
- ?>
For switch implementation
-
- 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'
';
- }
- ?>
While if implementation While switch implementation
-
- $ 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 ++;
- }
- ?>
Implement 0 01 010 0101 ...... 0 01 012 0123 3210 210 10 0 Make a calculator Such as test. php? A = 1 & B = 2 & operator = jia output 3 Such as test. php? A = 5 & B = 2 & operator = jian output 3 Such as test. php? A = 2 & B = 5 & operator = cheng output 10 Such as test. php? A = 6 & B = 3 & operator = chu output 2
- $ A = $ _ GET ['A'];
- $ B = $ _ GET ['B'];
- $ Operator = $ _ GET ['operator'];
- Function calculate ($ a, $ B, $ operator ){
- Switch ($ operator ){
- Case 'ja ':
- $ Result = $ a + $ B;
- Return $ result;
- Break;
- Case 'jian ':
- $ Result = $ a-$ B;
- Return $ result;
- Break;
- Case 'hangzhou ':
- $ Result = $ a * $ B;
- Return $ result;
- Break;
- Case 'chu ':
- $ Result = $ a/$ B;
- Return $ result;
- Break;
- }
- }
- Echo calculate ($ a, $ B, $ operator );
- ?>
The above is all the content of this article. I hope you will like it. |