PHP学习之制作乘法口诀表
进入学习php语言状态。昨日看了一天视频。才能够把这个小口诀表实现。好难啊。
成都创新互联专注于邢台网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供邢台营销型网站建设,邢台网站制作、邢台网页设计、邢台网站官网定制、小程序定制开发服务,打造邢台网络公司原创品牌,更为您提供邢台网站排名全网营销落地服务。
里面有个口诀表的函数、
"; for ($a=1;$a<=9;$a++){ //循环输出a a默认值是1 a的值不会大于9 且不断加一 for ($b=1;$b<=$a;$b++){//{b默认值是1 且b值不能大于a值 也就是九 加一运算 /*一开始a等于1的,满足$a<=9 往下运行,b=1,满足$b<=$a,输出echo "$b x $a = $c" ; 当b加一运算后,,不能满足$b<=$a,跳出循环,运行echo "
" 回到$a 循环,a加一 运算 此时a=2 满足$a<=9 。往下运行,b=1,满足$b<=$a,输出echo "$b x $a = $c",输出后 b加一运算了 等于2还是满足$b<=$a ,继续往下运行,b=2,满足$b<=$a,输出echo "$b x $a = $c" */ $c=$a*$b; //定义变量C的值 echo "$b x $a = $c" ; //输出变量b x 变量a 等于变量c echo " "; //空格 } echo "
"; //回车 } /*以上几句代码实现99乘法表 1 x 1 = 1 1 x 2 = 2 2 x 2 = 4 1 x 3 = 3 2 x 3 = 6 3 x 3 = 9 1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16 1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49 1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64 1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81 */ ?> "; for ($x=9;$x>=1;$x-- ){ for ($y=9;$y>=$x;$y--){ $z=$x*$y; echo "$y X $x =$z"; echo " "; } echo "
"; } ?> "; function cheng($a,$b=9){ //a是一个乘数;b是另一个乘数,初始值是9 for ($x=$a;$x<=$b;$x++){ for ($y=1;$y<=$x;$y++){ $z=$y*$x; echo "$y X $x =$z"; echo " "; } echo "
"; } } echo cheng(3,7); 调用了函数 echo "=============================================
"; echo cheng(1 ); //**********乘法表函数********* ?>
网站栏目:PHP学习之制作乘法口诀表
URL分享:http://cdiso.cn/article/jhpshh.html