Home  >  Article  >  Backend Development  >  PHP array key value small example

PHP array key value small example

WBOY
WBOYOriginal
2016-07-25 08:51:26946browse
  1. $switching = array(
  2. 10, // key = 0
  3. 5 => 6,
  4. 3 => 7,
  5. 'a' => 4,
  6. 11, / / key = 6 (the maximum value of the integer key index in the entire array is 5)
  7. '8' => 2, // key = 8 (the string key '8' is converted to 8)
  8. '02' => 77, // key = '02' (note not 2)
  9. 0 => 12
  10. /*The previous key with a value of 10 is assigned 0, and later the value of the 0 key is redefined to 12,
  11. thus overwriting the previous one Default 0 key value */
  12. );
  13. // empty array
  14. $empty = array();
  15. ?>
Copy code

If printed with print_r($switching), the result is: Array ( [0] => 12 [5] => 6 [3] => 7 [a] => 4 [6] => 11 [8] => 2 [02] => 77 ) Note that the two-digit number 02 is sorted behind.



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