: This article describes how to convert a two-dimensional php array to a string. For more information about PHP tutorials, see.
// The two-dimensional array is converted into a string, which is used in the middle to separate function arr_to_str ($ arr) {foreach ($ arr as $ v) {$ v = join (",", $ v); // you can use implode to convert a one-dimensional array to a comma-connected string. join is an alias $ temp [] = $ v;} foreach ($ temp as $ v) {$ t. = $ v. "," ;}$ t = substr ($ t, 0,-1); // use the string truncation function to remove the last comma return $ t ;}
PS:
Substr application
$ Str = "1, 2, 4, 5, 6,"; $ newstr = substr ($ str, 0, strlen ($ str)-1); echo $ newstr;
The built-in functions of the system can also achieve the following two methods:
1) substr ($ str, 0,-1 );
2) rtrim ($ str ,",")Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The preceding section describes how to convert a two-dimensional php array to a string, including some content. if you are interested in the PHP Tutorial.