Blogger Information
Blog 23
fans 0
comment 1
visits 16026
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php基础-常用数组的应用(2018年8月24日)
大白鲸的博客
Original
663 people have browsed it

作业1:

数组与变量与字符串的转换

实例

<?php
@header("content-Type: text/html; charset=utf-8");

//数组与变量与字符串之间的转换
//1.list() 把数组中的元素转为变量:用在索引数组上
list($name,$course,$grade)=['小龙女','php',80];
//$name = '小龙女';
//$course = 'php';
//$grade = 80;
echo $name, '的“',$course,'”课程的成绩是:',$grade,'<hr>';

//2.extract($arr,$flag):关联数组转为变量
$arr1 = ['id'=>1,'name'=>'杨过','sex'=>'male','salary'=>8000];
//extract():返回变量的数量
echo '共生成了:',var_export(extract($arr1), true),'个变量:<br>';
echo '我的id:',$id,',姓名:',$name,',性别:',$sex,',工资:',$salary,'元<hr>';
//3.compact():将变量转为数组
$name = '陈近南';
$faction = '天地会';
$position = '总舵主';
$arr = compact('name','faction','position');
echo var_export($arr,true),'<hr>';
//4.explode():将字符串转换数组
$lang = '放心 ,苹果手机,javascript,jquery,php,mysql';
echo var_export(explode(',',$lang)),'<br>';
echo var_export(explode(',',$lang,3)),'<br>';
echo var_export(explode(',',$lang,-2)),'<br>';

//5.implode($glue,$arr)
$arr = ['首页','公司新闻','公司动态','联系我们'];
echo var_export(implode($arr),true),'<br>';
echo var_export(implode('|',$arr),true),'<br>';
//添加<a>转为导航
echo var_export('<a href = "#">'.implode('</a>|<a href="#">',$arr).'</a>'),'<br>';

运行实例 »

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


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