explode函数如何在PHP中使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
<?php $province = array("北京","上海","天津","重庆","河北","山西","内蒙古","辽宁","吉林","黑龙江","江苏","浙江","安徽","福建","江西","山东","河南","湖北","湖南","广东","广西","海南","四川","贵州","云南","西藏","陕西","甘肃","宁夏","青海","新疆","香港","澳门","台湾","其他"); echo count($province);//数组成员个数 echo "<br/>"; if(is_array($province)){//检测变量是否是数组 echo "嗯,真是个数组啊"; } echo "</br>"; for($index=0;$index<count($province);$index++){//数组循环 echo $province[$index]; echo "</br>"; } ?>
例2:
<?php //利用 explode 函数分割字符串到数组 $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串 $hello = explode(',',$source); for($index=0;$index<count($hello);$index++){ echo $hello[$index];echo "</br>"; } ?>
例3:
<?php //函数挺实用的 // 分隔符可以是斜线,点,或横线 $date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>
看完上述内容,你们掌握explode函数如何在PHP中使用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。