Blogger Information
Blog 24
fans 0
comment 0
visits 16265
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
流程控制实战与常用数组函数-2018年8月23日
鱼越龙门的博客
Original
644 people have browsed it

今天学习了流程控制实战与常用数组函数的基本知识。

代码:

实例

<?php
$i=0;
while($i<10){
    echo $i<9?$i.',':$i;
    $i++;
}
echo '<hr>';

do{
    echo $i<9?$i.'.':$i;
    $i++;
}while($i<10);

运行实例 »

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

实例

<?php
function wel(){
    return '欢迎来到中国';
}
echo wel();
echo '<hr>';
function wel1($name){
    return '欢迎'.$name.'来到中国';
}
echo wel1('tom');
echo '<hr>';
function wel2($lang,$name='tom'){
    return '欢迎'.$name.'来到中国学习'.$lang;
}
echo wel2('中文');
echo '<hr>';
function wel3(){
   // return print_r(func_get_args(),true);
   // return func_num_args();
    return func_get_arg(2);
}
echo wel3(4,5,6);
echo '<hr>';
$name="tom";
function wel4(){
   global $name;
   return $name;
    // return $GLOBALS['name'];
}
echo wel4();

运行实例 »

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

实例

<?php
$person=['id'=>4,'name'=>'jim','age'=>18,'gender'=>'man'];
echo '<pre>';
echo print_r($person,true);

echo in_array('man',$person)?'存在':'不存在';
echo array_key_exists('age',$person)?'存在':'不存在';
echo print_r(array_values($person),true);
echo print_r(array_keys($person),true);
echo array_search('jim',$person);
echo print_r(array_flip($person),true);


echo count($person);
echo key($person);
echo current($person);
next($person);
echo key($person);
echo current($person);
reset($person);
echo key($person);
echo current($person);
end($person);
echo key($person);
echo current($person);
reset($person);
echo '<hr>';
//print_r(each($person));
list($key,$value)=each($person);
echo $key,'*******',$value.'<br>';
reset($person);
while(list($key,$value)=each($person)){
    echo $key,'*******',$value.'<br>';
}

运行实例 »

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

实例

<?php
$person=['id'=>4,'name'=>'jim','age'=>18,'gender'=>'man'];
echo '<pre>',print_r($person,true);
array_push($person,'80');
print_r($person);
array_pop($person);
print_r($person);
echo '<hr>';
array_unshift($person,100);
print_r($person);
array_shift($person);
print_r($person);
echo '<hr>';
array_push($person,79);
array_shift($person);
print_r($person);
echo '<hr>';
array_unshift($person,60);
array_pop($person);
print_r($person);

运行实例 »

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


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
Author's latest blog post