Blogger Information
Blog 48
fans 0
comment 0
visits 36387
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组函数 堆栈
雨天的博客
Original
807 people have browsed it

实例

<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2018/8/24
 * Time: 14:20
 */
for($i=0;$i<10;$i++)
{
   echo ($i<9) ? $i.',' : $i;
}
echo '<hr>';
//初始化条件 while(){更新条件}
$i=0;
while($i<10)
{
    echo ($i<9) ? $i.',' : $i;
    $i++;
}
echo '<hr>';
//初始化条件do{更新条件}while();
$i=10;
do{
    echo ($i<9) ? $i.',' : $i;
    $i++;
}while($i<10);
//while 和do{}while() 区别是:do while 条件错误至少执行一次
echo '<hr>';
//函数中参数有可选参数的时候,必须把必选参数放前面
function myFn()
{
    return 'Hello Word!';
}
echo myFn();
echo '<br>';
function myFn1($name,$k='')
{
    return $k.$name.'是超文本预处理语言'.$k;
}
echo myFn1('php','<br>');
echo '<br>';
function myFn2($a,$b,$c)
{
    return $a+$b+$c;
    //return func_get_arg(1);//获取第n个参数的值
   // return func_num_args();//获取参数的数量
    //return print_r(func_get_args()); //获取所有参数
}
echo myFn2(3,4,6);
echo '<br>';
$arr=['name'=>'Tom','age'=>22,'sex'=>'男'];
echo '<br>';
//in_array 判断数组中是否存在某个值
echo in_array('Tom',$arr) ? '存在' : '不存在';
echo '<br>';
//array_search() 返回指定值的键名
echo array_search(22,$arr);
echo '<br>';
//array_key_exists() 判断键名是否存在数组中
echo array_key_exists('age',$arr) ? '存在' : '不存在';
echo '<br>';
echo '<pre>';
//array_keys() 以索引数组的形式返回当前数组的键名
print_r(array_keys($arr));
echo '<br>';
echo '<pre>';
//array_values() 以索引数组的形式返回当前数组的值
print_r(array_values($arr));
echo '<br>';
echo '<pre>';
//array_flip 数组键值对调
print_r(array_flip($arr));
echo '<br>';
//cout() 统计数组元素的数量
echo count($arr);
echo '<br>';
//key() 键名
echo key($arr);
echo '<br>';
//current() 值
echo current($arr);
echo '<br>';
//next() 指针下移
next($arr);
echo key($arr).'=>'.current($arr);
echo '<br>';
//指针复位
reset($arr);
echo key($arr).'=>'.current($arr);
echo '<br>';
//end() 结尾
end($arr);
echo key($arr).'=>'.current($arr);
echo '<br>';
reset($arr);
//while list each
while (list($key,$value)=each($arr))
{
    echo $key.'=>'.$value.'<br/>';
}
echo '<br>';
$arrName=['php','html','java'];
echo array_push($arrName,'css');//返回数组的长度
echo '<br>';
echo array_pop($arrName);//从尾部出
echo '<br>';
echo array_unshift($arrName,'access');//返回数组的长度
echo '<br>';
echo array_shift($arrName);//从头部出
echo '<br>';
//模拟队列操作:增删只能在两端进行,不允许同一段进行
array_push($arrName,'css');
print_r($arrName);
echo '<br>';

array_shift($arrName);
print_r($arrName);
echo '<br>';

array_unshift($arrName,'access');
print_r($arrName);
echo '<br>';
$table='<table border="0" cellspacing="0" cellpadding="0" width="500">';
for($i=1;$i<=9;$i++)
{
    $table.='<tr>';
    for ($j=1;$j<=$i;$j++)
    {
        $table.='<th style="border: solid 1px #ccc; margin-bottom: 5px;height: 20px;">'.$i.'*'.$j.'='.$i*$j.'</th>';
    }
    $table.='</tr>';
}
$table.='</table>';
echo $table;

运行实例 »

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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!