Blogger Information
Blog 33
fans 0
comment 0
visits 20819
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
while循环、函数参数、数组操作2018年8月24日
马聪 15558002279的博客
Original
793 people have browsed it
  1. while 和do while:


    实例

    <?php
    $a = 0;
    while ($a<=10) {
    	echo $a++;
    }
    echo "<br>";
    $a=0;
    do {
    	echo ++$a;
    }while($a<=10);
    ?>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

  2. 函数传参:

    实例

    <?php
    echo "<br><hr>";
    function fn1($search,$mes="找到了"){
    	$arr = array();
    	for ($i=0; $i <=5; $i++) { 
    		$arr[$i] = $i+1;
    		if($arr[$i]==$search){
    			echo "{$mes}值为{$search}的元素是第{$i}个";
    		}
    	}
    	 
    }
    fn1(3);
    ?>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

    3.数组操作:


  3. 实例

    <?php
    //创建一个数组
    $b=1;
    $arr=array();
    while ($b<= 30) {
    	echo $b;
    	array_push($arr,$b+100);
    	$b++;
    }
    //var_dump($arr);
    //对数组操作
    $b=1;
    while ($b<= 30) {
    	echo "<br>键为",key($arr),"值为",current($arr);
    	next($arr); //指针下移动
    	//指针到15就重置
    	if(key($arr) == 15){ 
    		reset($arr);
    	}
    	if($b>15){
    		echo "数组内的值都抛光了";
    		break;
    	}else{	
    	echo "<hr>";
    	echo "抛出尾部值为".array_pop($arr)."的元素*****";//抛出最后一个
    	echo "抛出头部值为".array_shift($arr);//抛出键最小的
    	echo "<hr>";
    	}
    	$b++;
    }
    ?>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post