Blogger Information
Blog 11
fans 0
comment 0
visits 7656
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php的学习第四课(常用数组函数二)-2018年8月26日21点10分
victor的博客
Original
709 people have browsed it

代码作业:

实例

$heros = [];    //声明一个空数组,后面的值通过追加的方式,添加进去
$heros['name'] = 'ooo';
$heros['title'] = 'ooooooooo';
$heros['advantages'] = 'zzzz';
//echo '<pre>' .print_r($heros, true);

//  遍历数组
$res1 = '';
for( $i=0; $i<count($arts); $i++){
//    print_r( $arts[$i] );
    $res1 .= $arts[$i] . ',';
}
echo $res1;
echo '<hr/>';
echo rtrim( $res1, ',' );   //删除右侧指定字符

//数组回调

$arr3 = ['html', 'css', 'javascript'];
$arr4 = array_filter($arr3, function($value){
    return $value !== 'css';
});
echo var_export($arr4);

compact()    将变量转为数组
$name= 'xxx';
$factory= 'fffff';
$position= 'ppp';
$arr2 = compact('name','factory','position');
echo var_export($arr2, true);

//将字符串转为数组 explode()
$lang = 'html,css,javascript,jquery';
echo '<pre>' . var_export(explode(',', $lang)) . '</pre>';

运行实例 »

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


Correction status:qualified

Teacher's comments:实例中的PHP标签都没带哦
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