PHP array to a character string (attribute and single (double) quotes, commas)

$ Data array

$ data = array ( 'John Doe', 'M', '20 ',' Hefei ');

converted as follows:
#join
. STR $ = "'" the Join ( " ''", array_values ($ data)) " '"; // need to use symbols splicing.

#str_replace
$ STR = "'" .str_replace ( ",", " ','", the implode ( ',', $ Data)); // use Alternatively the required symbols

#array_map functional achieved
$ str = join ( ',' , array_map (function ($ v) {return " '" "" $ v..';}, $ data)); // use the function splice
results: 'John Doe', 'male', '20', '' Hefei ';
----------------
Disclaimer: This article is CSDN bloggers' youcijibi " the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/youcijibi/article/details/81015004

Guess you like

Origin www.cnblogs.com/bit5566/p/12185492.html