How to deal with the problem of generating an associated array using array which is a string in parentheses

Source: Internet
Author: User
What should I do if I use array to generate an associated array which is a string in parentheses? Yes. the values read from the database are: & quot; Peter & quot; & gt; 32, & quot; Quagmire & quot; & gt; 30, & quot; joe & quot; & gt; 34 use array (& quot; Peter & quot; & gt; 32, & quot; Quagmire & quot; & gt; 30. what should I do if I use array to generate an associated array which is a string in parentheses?
The value read from the database is:
"Peter" => 32, "Quagmire" => 30, "Joe" => 34
Use array ("Peter" => 32, "Quagmire" => 30, "Joe" => 34) to change it to an associated array, but the values are strings, is there a way to remove string attributes? Or is there any other way to save it?

Thank you very much!

------ Solution --------------------
PHP code
  32, "Quagmire" => 30, "Joe" => 34'; eval ('$ arr = array ('. $ str. '); print_r ($ arr );

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.