Recently I encountered a problem when writing MVC: You can use implode to quickly combine PHP arrays into strings. But what if I want to quickly output the key value to a string? The temporary method is to cyclically assume that there is a one-dimensional array $ a to store N contents. Code 1 :? Php $ B; foreach ($ aas $ key $ value) {$ B. $ key;} echo $ B ;? Write code 1
Recently I encountered a problem when writing MVC: You can use implode to quickly combine PHP arrays into strings. But what if I want to quickly output the key value to a string? The temporary method is to cyclically assume that there is a one-dimensional array $ a to store N contents. Code 1 :? Php $ B = ''; foreach ($ a as $ key = $ value) {$ B. = $ key;} echo $ B ;? Write code 1
Recently I encountered a problem when writing MVC: You can use implode to quickly combine PHP arrays into strings. But what if I want to quickly output the key value to a string?
The temporary method is loop.
Suppose there is a one-dimensional array $ a that stores N contents.
Code 1:
$ Value) {$ B. = $ key;} echo $ B;?>
Code 1 is too painful to write, and PHP itself has a function implode that can quickly form an array into a string, so the key value is certainly acceptable. After reading the Array Function manual, find array_keys and return all the key values in the array directly. Manual address: http://docs.php.net/manual/en/function.array-keys.php
Code 2:
Haha, is the code much more concise? :)
Original article address: Quickly combines the PHP array key values into strings. Thank you for sharing it with the original author.