Blogger Information
Blog 12
fans 0
comment 0
visits 10513
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组与字符串变量之间的转换8月27日16:38
A骆长林的博客
Original
631 people have browsed it

实例

<meta charset="utf-8" />
<?php
//1.list()把数组转换为变量,用在索引数组上
list($name,$name1,$name2) = ['雪饼','大炮','清娃'];
echo $name."<br>";

$arrtt = ['id'=>1,'name1'=>'大炮','age'=>30];
//2. extract($arr, $flag): 关联数组转为变量
echo var_export(extract($arrtt),true).'<hr>';

//3.compact(); 将变量转化关联为数组
$id = 10;
$name2 = '清娃';
$age1 = 30;
$arr1 = compact('id','name2','age1');
echo "<pre>".var_export($arr1,true).'<hr>';

//4.explode():将字符串转换数组
//$lang = 'html,css,javascript,jquery,php,mysql';
//echo var_export(explode(',',$lang)),'<br>';
//echo var_export(explode(',',$lang,3)),'<br>';
//echo var_export(explode(',',$lang,-2)),'<br>';//最常用
$haha = 'html,css,javascript,jquery,php,mysql';
echo var_export(explode(',',$haha));
echo var_export(explode(',',$haha,3));
echo var_export(explode(',',$haha,-2)).'<hr>';//删除后面2个

//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>';
$arr5 = ['首页','服务项目','服务案例','新闻中心','联系我们'];
echo var_export(implode($arr5),true),'<br>';
echo var_export(implode('|',$arr5),true),'<br>';
echo var_export('<a href="#">'.implode('</a>|<a href="#">',$arr5).'</a>'),'<br>';

运行实例 »

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


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