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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:30:26
Original
1151 people have browsed it

通过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>
Copy after login
Related labels:
Statement of this Website
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
Latest Issues
explode function splits an array
From 1970-01-01 08:00:00
0
0
0
Explode array based on value
From 1970-01-01 08:00:00
0
0
0
Resize image before upload in Laravel 5.8
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template