Correction status:qualified
Teacher's comments:
一、概述
本节课讲述了while与do while、函数的参数、数组键值常见操作和指针、堆栈操作。
二、作业
1、while和do while以及函数部分
<?php echo '<h4 style="color : gold">有参数的函数</h4>'; function hello(){ return 'Hello~'; } function hello2($name,$age,$country='CHINA'){ echo hello(); return 'I\'m '.' '.$name.'.<br>'.'I\'m '.$age.'.<br>'.'I come from '.$country.'.<br>'; } echo hello2(Mike,19),'<hr>'; echo '<h4 style="color : red">无参数的函数</h4>'; function hello3(){ echo hello(); return 'I\'m '.' '.func_get_arg(0).'.<br>'. 'I\'m '.func_get_arg(1). '.<br>'.'I come from '.func_get_arg(2).'.<br>'; } echo hello3(Jack,20,USA),'<hr>'; echo '<h4 style="color : coral">全局变量不可以直接调用</h4>'; $no=9981;$school='school'; function get_School(){ global $no; return 'I am in '.$no.$GLOBALS['school']; } echo get_school(),'<br>'; echo '<h4 style="color : gold">while和do while</h4>'; $i=1; while ($i<3){ // if ($i<2){ // echo hello3(Jack,20,USA),'<br>'; // } // if ($i==2){ // echo hello2(Mike,19); // } echo $i<2 ? hello3(Jack,20,USA).'<br>' : hello2(Mike,19); $i++; } echo '<hr>'; $i=1; do{ echo $i<2 ? hello3(Jack,20,USA).'<br>' : hello2(Mike,19); }while(i<0);
点击 "运行实例" 按钮查看在线实例
截图:
2、数组和堆栈
<?php echo '<h4 style="color : gold">键值对</h4>'; $std=['id'=>5,'name'=>mike,'class'=>9,'grade'=>3]; echo '<pre>',print_r($std,true),'</pre>'; echo '<hr>'; echo in_array('mike',$std) ? '有':'无'; echo '<hr>'; echo array_key_exists('name',$std) ? '有':'无'; echo '<hr>'; echo '<pre>',print_r(array_values($std),true),'</pre>'; echo '<hr>'; echo '<pre>',print_r(array_keys($std),true),'</pre>'; echo '<hr>'; $key2 = array_search('mike',$std); echo $key2,'<br>'; echo $std[$key2]; echo '<h4 style="color : gold">指针</h4>'; $school=['id'=>5,'name'=>A,'class'=>9,'grade'=>3]; echo '<pre>',print_r($school,true),'</pre>'; echo '当前元素数目',count($school),'<br>'; echo '当前key',key($school),'<br>'; echo '当前值',current($school),'<br>'; next($school); echo '指针下移动,当前key',key($school),'<br>'; echo '当前值',current($school),'<br>'; reset($school); echo '数组重置,当前key',key($school),'<br>'; echo '当前值',current($school),'<br>'; end($school); echo '指针移动最后,当前key',key($school),'<br>'; echo '当前值',current($school),'<br>'; reset($school); echo '<pre>','返回当前元素的键值的索引与关联的描述,并自动下移', print_r(each($school),true),'</pre>'; reset($school); list($key0,$value0) = each($school); echo $key0,'-----',$value0,'<br>'; list($key0,$value0) = each($school); echo $key0,'-----',$value0,'<br>'; list($key0,$value0) = each($school); echo $key0,'-----',$value0,'<br>'; list($key0,$value0) = each($school); echo $key0,'-----',$value0,'<br>'; list($key0,$value0) = each($school); echo $key0,'-----',$value0,'<hr>'; reset($school); echo '遍历数组','<br>'; while (list($key0, $value0) = each($school)) { echo $key0 , ' => ', $value0, '<br>'; } echo '<h4 style="color : gold">堆栈和队列</h4>'; reset($school); echo '<pre>',print_r($school,true),'</pre>'; echo count($school),'<br>'; echo array_push($school,location),'<br>'; echo count($school),'<br>'; echo '<pre>',print_r($school,true),'</pre>'; echo array_pop($school),'<br>';//删除最后一个元素 echo array_pop($school),'<br>'; echo array_pop($school),'<br>'; echo '<pre>',print_r($school,true),'</pre>'; reset($school); echo '<pre>',print_r($school,true),'</pre>'; echo array_unshift($school,'class','grade'); echo '<pre>',print_r($school,true),'</pre>'; echo array_shift($school); echo '<pre>',print_r($school,true),'</pre>'; echo '<h4 style="color : gold">尾进头出</h4>'; array_push($school,'no'); echo '<pre>',print_r($school,true),'</pre>'; array_shift($school); echo '<pre>',print_r($school,true),'</pre>'; echo '<h4 style="color : gold">头进尾出</h4>'; array_unshift($school,'class'); echo '<pre>',print_r($school,true),'</pre>'; array_pop($school); echo '<pre>',print_r($school,true),'</pre>'; echo '<br><br><br><br><br><br><br><br><br>';
点击 "运行实例" 按钮查看在线实例
截图:
三、总结
本节课内容基本掌握,明白了用法,对基础能力进一步夯实,数组部分只做到了看到会明白是什么意思,入栈和出栈操作只需记忆即可。