实例
<meta charset="utf-8"> <!--一、数组数组与字符串变量之间的转换--> <h3>数组与字符串变量之间的转换</h3> <?php list($name, $course, $grade) = ['小龙女','php',80]; echo $name,'的"',$course,'"课程成功是:',$grade ,'<hr>'; //关联数组 $arr1 = ['id'=>1,'name'=>'杨过','sex'=>'male','salary'=>8000]; echo var_export(extract($arr1),true); echo $id,$name,$sex,$salary; echo '<hr>'; //3.compact(): 将变量转为关联数组 $name = '陈近南'; $fation = '天地会'; $position = '总的主'; $arr = compact('name','fation','position'); echo var_export($arr,true),'<hr>'; //4.explode 将字符串转换成数组 echo '<pre>'; $lang = 'c,php,c++,java,css,go'; echo var_export(explode(',',$lang)),'<br>'; echo var_export(explode(',',$lang,3)),'<br>'; echo var_export(explode(',',$lang,-2)),'<br>'; //5.implode 分散拼接 $arr = ['good','morning','big','and']; echo var_export(implode('_',$arr)); //二、数组元素回掉 $arr1 = [5,2,'',null,22,false,'php']; echo '<pre>'; echo var_export($arr1,true),'<br>';
运行实例 »
点击 "运行实例" 按钮查看在线实例