Home  >  Article  >  Backend Development  >  How to convert php two-dimensional array to string

How to convert php two-dimensional array to string

藏色散人
藏色散人Original
2021-11-30 10:03:383665browse

php method to convert a two-dimensional array into a string: 1. Create a PHP sample file; 2. Use implode to convert the one-dimensional array into a string connected with commas; 3. Then use the arr2str method to convert the two-dimensional array into a string. Just convert the dimensional array into a string.

How to convert php two-dimensional array to string

The operating environment of this article: windows7 system, PHP7.4 version, DELL G3 computer

php two-dimensional array to string example

The code is as follows:

function arr2str ($arr)
{
    foreach ($arr as $v)
    {
        $v = join(",",$v); //可以用implode将一维数组转换为用逗号连接的字符串
        $temp[] = $v;
    }
    $t="";
    foreach($temp as $v){
        $t.="'".$v."'".",";
    }
    $t=substr($t,0,-1);
    return $t;
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert php two-dimensional array to string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn