1--TEST-- 2General function test 3--FILE-- 4<?php 5 6function a() 7{ 8 echo "hey\n"; 9} 10 11function b($i) 12{ 13 echo "$i\n"; 14} 15 16 17function c($i,$j) 18{ 19 echo "Counting from $i to $j\n"; 20 for ($k=$i; $k<=$j; $k++) { 21 echo "$k\n"; 22 } 23} 24 25 26 27a(); 28b("blah"); 29a(); 30b("blah","blah"); 31c(7,14); 32 33a(); 34 35 36function factorial($n) 37{ 38 if ($n==0 || $n==1) { 39 return 1; 40 } else { 41 return factorial($n-1)*$n; 42 } 43} 44 45 46function factorial2($start, $n) 47{ 48 if ($n<=$start) { 49 return $start; 50 } else { 51 return factorial2($start,$n-1)*$n; 52 } 53} 54 55 56for ($k=0; $k<10; $k++) { 57 for ($i=0; $i<=10; $i++) { 58 $n=factorial($i); 59 echo "factorial($i) = $n\n"; 60 } 61} 62 63 64echo "and now, from a function...\n"; 65 66function call_fact() 67{ 68 echo "(it should break at 5...)\n"; 69 for ($i=0; $i<=10; $i++) { 70 if ($i == 5) break; 71 $n=factorial($i); 72 echo "factorial($i) = $n\n"; 73 } 74} 75 76function return4() { return 4; } 77function return7() { return 7; } 78 79for ($k=0; $k<10; $k++) { 80 call_fact(); 81} 82 83echo "------\n"; 84$result = factorial(factorial(3)); 85echo "$result\n"; 86 87$result=factorial2(return4(),return7()); 88echo "$result\n"; 89 90function andi($i, $j) 91{ 92 for ($k=$i ; $k<=$j ; $k++) { 93 if ($k >5) continue; 94 echo "$k\n"; 95 } 96} 97 98andi (3,10); 99--EXPECT-- 100hey 101blah 102hey 103blah 104Counting from 7 to 14 1057 1068 1079 10810 10911 11012 11113 11214 113hey 114factorial(0) = 1 115factorial(1) = 1 116factorial(2) = 2 117factorial(3) = 6 118factorial(4) = 24 119factorial(5) = 120 120factorial(6) = 720 121factorial(7) = 5040 122factorial(8) = 40320 123factorial(9) = 362880 124factorial(10) = 3628800 125factorial(0) = 1 126factorial(1) = 1 127factorial(2) = 2 128factorial(3) = 6 129factorial(4) = 24 130factorial(5) = 120 131factorial(6) = 720 132factorial(7) = 5040 133factorial(8) = 40320 134factorial(9) = 362880 135factorial(10) = 3628800 136factorial(0) = 1 137factorial(1) = 1 138factorial(2) = 2 139factorial(3) = 6 140factorial(4) = 24 141factorial(5) = 120 142factorial(6) = 720 143factorial(7) = 5040 144factorial(8) = 40320 145factorial(9) = 362880 146factorial(10) = 3628800 147factorial(0) = 1 148factorial(1) = 1 149factorial(2) = 2 150factorial(3) = 6 151factorial(4) = 24 152factorial(5) = 120 153factorial(6) = 720 154factorial(7) = 5040 155factorial(8) = 40320 156factorial(9) = 362880 157factorial(10) = 3628800 158factorial(0) = 1 159factorial(1) = 1 160factorial(2) = 2 161factorial(3) = 6 162factorial(4) = 24 163factorial(5) = 120 164factorial(6) = 720 165factorial(7) = 5040 166factorial(8) = 40320 167factorial(9) = 362880 168factorial(10) = 3628800 169factorial(0) = 1 170factorial(1) = 1 171factorial(2) = 2 172factorial(3) = 6 173factorial(4) = 24 174factorial(5) = 120 175factorial(6) = 720 176factorial(7) = 5040 177factorial(8) = 40320 178factorial(9) = 362880 179factorial(10) = 3628800 180factorial(0) = 1 181factorial(1) = 1 182factorial(2) = 2 183factorial(3) = 6 184factorial(4) = 24 185factorial(5) = 120 186factorial(6) = 720 187factorial(7) = 5040 188factorial(8) = 40320 189factorial(9) = 362880 190factorial(10) = 3628800 191factorial(0) = 1 192factorial(1) = 1 193factorial(2) = 2 194factorial(3) = 6 195factorial(4) = 24 196factorial(5) = 120 197factorial(6) = 720 198factorial(7) = 5040 199factorial(8) = 40320 200factorial(9) = 362880 201factorial(10) = 3628800 202factorial(0) = 1 203factorial(1) = 1 204factorial(2) = 2 205factorial(3) = 6 206factorial(4) = 24 207factorial(5) = 120 208factorial(6) = 720 209factorial(7) = 5040 210factorial(8) = 40320 211factorial(9) = 362880 212factorial(10) = 3628800 213factorial(0) = 1 214factorial(1) = 1 215factorial(2) = 2 216factorial(3) = 6 217factorial(4) = 24 218factorial(5) = 120 219factorial(6) = 720 220factorial(7) = 5040 221factorial(8) = 40320 222factorial(9) = 362880 223factorial(10) = 3628800 224and now, from a function... 225(it should break at 5...) 226factorial(0) = 1 227factorial(1) = 1 228factorial(2) = 2 229factorial(3) = 6 230factorial(4) = 24 231(it should break at 5...) 232factorial(0) = 1 233factorial(1) = 1 234factorial(2) = 2 235factorial(3) = 6 236factorial(4) = 24 237(it should break at 5...) 238factorial(0) = 1 239factorial(1) = 1 240factorial(2) = 2 241factorial(3) = 6 242factorial(4) = 24 243(it should break at 5...) 244factorial(0) = 1 245factorial(1) = 1 246factorial(2) = 2 247factorial(3) = 6 248factorial(4) = 24 249(it should break at 5...) 250factorial(0) = 1 251factorial(1) = 1 252factorial(2) = 2 253factorial(3) = 6 254factorial(4) = 24 255(it should break at 5...) 256factorial(0) = 1 257factorial(1) = 1 258factorial(2) = 2 259factorial(3) = 6 260factorial(4) = 24 261(it should break at 5...) 262factorial(0) = 1 263factorial(1) = 1 264factorial(2) = 2 265factorial(3) = 6 266factorial(4) = 24 267(it should break at 5...) 268factorial(0) = 1 269factorial(1) = 1 270factorial(2) = 2 271factorial(3) = 6 272factorial(4) = 24 273(it should break at 5...) 274factorial(0) = 1 275factorial(1) = 1 276factorial(2) = 2 277factorial(3) = 6 278factorial(4) = 24 279(it should break at 5...) 280factorial(0) = 1 281factorial(1) = 1 282factorial(2) = 2 283factorial(3) = 6 284factorial(4) = 24 285------ 286720 287840 2883 2894 2905 291