Quickly combine PHP array key values into strings

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.