How to convert array to a string using methods other than JSON?

后端 未结 8 2153
臣服心动
臣服心动 2020-12-01 13:32

What is a function in PHP used to convert array to string, other than using JSON?

I know there is a function that directly does like JSON. I just don\'t remember.

8条回答
  •  心在旅途
    2020-12-01 14:06

    There are different ways to do this some of them has given. implode(), join(), var_export(), print_r(), serialize(), json_encode()exc... You can also write your own function without these:

    A For() loop is very useful. You can add your array's value to another variable like this:

    
    

    In this code we added $dizi's values and comma to $dizin:

    $dizin.=("'$dizi[$i]',");

    Now

    $dizin = 'mother', 'father', 'child',
    

    It's a string, but it has an extra comma :)

    And then we deleted the last comma, substr($dizin, 0, -1);

    Output:

    'mother','father','child'

提交回复
热议问题