Home >Backend Development >PHP Tutorial > 通过explode函数分割字符串成数组,怎么让索引从1开始

通过explode函数分割字符串成数组,怎么让索引从1开始

WBOY
WBOYOriginal
2016-06-13 13:30:261104browse

通过explode函数分割字符串成数组,如何让索引从1开始
通过explode函数分割字符串成数组,如何让索引从1开始

------解决方案--------------------

PHP code

<?php $str = "1,2,3,4,5,6";
$a = explode(',',$str);

$b = Array();
foreach($a as $key=>$val){
    $b[$key+1] = $val;
}
print_r($a);
print_r($b);
?> <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn