Php operation string to array

Source: Internet
Author: User
Today, I saw a post in the php forum asking my friend how to convert a string into an array. As a new php programmer, the first response is to think of explode (), implode () these two functions. The new one is also converted to an array using the functions in it. Con [1] 28 selt [1] 1con [2] 29 selt [2] 4con [3] 26 selt [3] 4con [4] 30 s

Today, I saw a post in the php forum asking my friend how to convert a string into an array. As a new php programmer, the first response is to think of explode (), implode () these two functions. The new one is also converted to an array using the functions in it. Con [1] = 28 selt [1] = 1con [2] = 29 selt [2] = 4con [3] = 26 selt [3] = 4 con [4] = 30 s

Today, I saw a post in the php forum asking my friend how to convert a string into an array. As a new php programmer, the first response is to think of explode (), implode () these two functions. The new one is also converted to an array using the functions in it.

Con [1] = 28 & selt [1] = 1 & con [2] = 29 & selt [2] = 4 & con [3] = 26 & selt [3] = 4

& Con [4] = 30 & selt [4] = 2 & con [5] = 4 & selt [5] = 1 & con [6] = 11 & con [7] = 12

The above is the string that netizens need to convert to the PHP array; below is the new PHP conversion code

 $ V) {$ arr = explode ('=', $ v); $ arr2 [$ k] = $ arr [1];} print_r ($ arr2);?> // Output Array ([0] => 28 [1] => 1 [2] => 29 [3] => 4 [4] => 26 [5] => 4 [6] => 30 [7] => 2 [8] => 4 [9] => 1 [10] => 11 [11] => 12) // second
 $ V) {$ arr = explode ('=', $ v); $ arr2 [$ arr [0] = $ arr [1];} print_r ($ arr2);?> // Output Array ([con [1] => 28 [selt [1] => 1 [con [2] => 29 [selt [2] => 4 [con [3] => 26 [selt [3] => 4 [con [4] => 30 [selt [4] => 2 [con [5] => 4 [selt [5] => 1 [con [6] => 11 [con [7] => 12)

The new PHP code can also solve the problem of converting strings into arrays. Finally, phper users should find the parse_str () function in the manual to convert the string into a PHP array. The following describes the description of the parse_str () function to impress themselves.
The parse_str () function parses the query string to a variable.

Parse_str (string, array) string: string to be converted; array: returned to an array; If array is not set, the variable with the same name is overwritten.

Original article address: Convert the php operation string to an array. Thank you for sharing it.

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.