Table of Contents
PHP数组,$a = {0,1,2,3}怎样变成$a = {1,2,3,4]
Jun 23, 2016 pm 02:00 PM
1
2
3
PHP数组,$a = {0,1,2,3}怎样变成$a = {1,2,3,4]。就是多维数组的维,然后把维加1,输出成表格的序列号,1,2,3,4
回复讨论(解决方案)
$a = array(0, 1, 2, 3);$b = range(1, count($a));$c = array_combine($b, $a);print_r($c);
Copy after login
(
[1] => 0
[2] => 1
[3] => 2
[4] => 3
)
$arr = array(0,1,2,3);$temp = array();foreach($arr as $k=>$v){ $k++; $temp[] = $k;}print_r($temp);
Copy after login
版主的更漂亮!
版主的思路漂亮,这里提供另一种思路。
<?php$a = array(0,1,2,3);array_unshift($a, 0); // 在数组开头插入一个新元素,使key自增1unset($a[0]); // 删除开头新增的元素,但key保持不变print_r($a); // 输出?>
Copy after login
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

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to determine how many arrays there are in php

gateio exchange official website entrance Sesame door gate official website entrance

Effective implementation of array union in PHP

An exploration of performance optimization techniques for PHP arrays

gate official website login portal gate.io login web version

What is the function in PHP to determine if an array is empty?

Will shuffling the order of PHP array affect the reference or address of the array?
