Blogger Information
Blog 17
fans 0
comment 0
visits 11931
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
while/do..while/函数/数组键值操作与指针操作/数组模拟栈与队列操作 2018-08-24 16:30
Aken的博客
Original
732 people have browsed it

实例

<?php
/**
 * while 与 do  while
 */

$a = 5;
while($a<10){
//    if($a<9){
//        echo $a,',';
//    }else{
//        echo $a;
//    }
    echo $a<9 ? $a.',' : $a;
    $a++;
}

echo '<hr>';
$b = 10;
do{
    echo $b;
    $b++;
}while($b<10);

运行实例 »

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


实例

<?php
/**
 * function
 */

function abc(){
    return 'hello world';
}
echo abc().'<br>';

function sayName($name){
    return '我的名字是:'.$name;
}
echo sayName('张三');

echo '<hr>';
function select($name,$address='上海'){
    return $name.'是'.$address.'人';
}

echo select('张三');

运行实例 »

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


实例

<?php

$array = ['张三','李四','王五','赵六'];
echo in_array('张三',$array);   //判断数组中是否存在某个值
echo array_key_exists('0',$array) ? '存在':'不存在';  //判断键值是否存在于某个数组

print_r(array_values($array)); //以索引方式返回数组的值组成的数组

print_r(array_keys($array));

$user = ['id'=>1, 'name'=>'bob','gender'=>'male','age'=>20];
echo $user[array_search('bob',$user)];

print_r(array_flip($user));

echo count($user),'<br>';

echo key($user),'<br>';

echo current($user),'<hr>';

next($user);

echo key($user),'<br>';

echo current($user),'<hr>';

reset($user);

echo key($user),'<br>';

echo current($user),'<hr>';

end($user);

echo key($user),'<br>';

echo current($user),'<br>';

运行实例 »

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


实例

<?php 
$array = ['张三','李四','王五','赵六'];
array_push($array);    //向数组末尾添加单元
array_pop($array);     //从数组末尾移除单元
array_unshift($array);   //向数组开始处插入单元
array_shift($array);   //从数组开始处移除单元

运行实例 »

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


Correction status:qualified

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