Heim  >  Artikel  >  Backend-Entwicklung  >  php数组键值小例子

php数组键值小例子

WBOY
WBOYOriginal
2016-07-25 08:51:26946Durchsuche
  1. $switching = array(
  2. 10, // key = 0
  3. 5 => 6,
  4. 3 => 7,
  5. 'a' => 4,
  6. 11, // key = 6 (整个数组中整型键索引最大的值是5)
  7. '8' => 2, // key = 8 (字符串健'8'转换为8)
  8. '02' => 77, // key = '02'(注意不是2)
  9. 0 => 12
  10. /*前面值为10的键被赋予0,而后面重新定义了0键的值为12,
  11. 从而覆盖了前面默认的0键值*/
  12. );
  13. // empty array
  14. $empty = array();
  15. ?>
复制代码

如果用print_r($switching)打印出来的话结果为: Array ( [0] => 12 [5] => 6 [3] => 7 [a] => 4 [6] => 11 [8] => 2 [02] => 77 ) 注意,两位数的02被排在后面。



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn