Blogger Information
Blog 20
fans 0
comment 0
visits 19645
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php使用explode需要注意的问题(空字符串)
大鱼
Original
3016 people have browsed it

<?php
$ids = null;$data = explode(',', $ids);?>

当ids=null,使用explode分割,得出的数组是Array ( [0] => )而不是Array()。
所以判断需要修改一下才能避免问题发生

<?php
$ids = null;$data = explode(',', $ids);if(isset($data[0]) && $data[0]){
   foreach($data as $k=>$v){
       // do sth
   }}?>


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