实例
<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>';
运行实例 »
点击 "运行实例" 按钮查看在线实例