Home > Backend Development > PHP Tutorial > 高手来看看

高手来看看

WBOY
Release: 2016-06-23 14:11:07
Original
809 people have browsed it

<?php// this$a = array( 'color' => 'red',           'taste' => 'sweet',           'shape' => 'round',           'name'  => 'apple',                      4        // key will be 0         );// is completely equivalent with$a['color'] = 'red';$a['taste'] = 'sweet';$a['shape'] = 'round';$a['name']  = 'apple';$a[]        = 4;        // key will be 0$b[] = 'a';$b[] = 'b';$b[] = 'c';// will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'),// or simply array('a', 'b', 'c')print_r($a);?>
Copy after login

输出结果是Array ( [color] => red [taste] => sweet [shape] => round [name] => apple [0] => 4 [1] => 5 )
重新索引$a[] 不是从$a变量里找最大整数吗..输出结果应该是[4]=>5啊



回复讨论(解决方案)

不解,是从key中找最大整数么

没有重新索引,如果数组没有定义下标,默认的下标是从0开始的
这里你下面的下标是字符串的,没有定义下标的他的下标就是从0开始了,没有重新索引啊
只是你这里怎么出现5啊?我怎么没发现有5啊

没有重新索引,如果数组没有定义下标,默认的下标是从0开始的
这里你下面的下标是字符串的,没有定义下标的他的下标就是从0开始了,没有重新索引啊
只是你这里怎么出现5啊?我怎么没发现有5啊
好吧我发现了。重新索引是从array (key=>value
                             ..)中key取值的..key是整数取最大key整数+1
版主,请问下标是什么.是key吗

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template