Array merge issues

Source: Internet
Author: User
$act _arr = Array (0=> ' AAA ',2=> ' BBB ');
I'm going to turn into the following string
' AAA ', ' BBB '
Use implode (', ', $act _arr);
The result is aaa,bbb.
How to use the fast method, it is best not to traverse, to achieve the effect I want.


Reply to discussion (solution)

To get single quotes, you should use escape characters!

echo "'". Implode (', ', $act _arr). "'";

That's right.
echo "'". Implode ("', '", $act _arr). "'";

Also to a

$act _arr = Array (0=> ' AAA ',2=> ' BBB '), $act _arr=array_map (' foo ', $act _arr), function foo ($v) {     return "' $v '";} echo implode (', ', $act _arr);

$str = "'". Implode ("', '", $act _arr). "'";

Understand, is to separate the comma (,), instead of ', ' separated on it can be

  • Related Article

    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.