String to Array and Back

后端 未结 9 2467
自闭症患者
自闭症患者 2020-12-22 07:19

I have a string, how do I convert it to an array?

After manipulating that array, how do I again make it into a string?

Do strings in PHP behave the same way

相关标签:
9条回答
  • 2020-12-22 07:39
    explode ( string $delimiter , string $string [, int $limit ] )
    

    ... and after changes ...

    implode ( string $glue , array $pieces )
    

    check out http://php.net/explode
    and http://php.net/implode

    You can also use split or join which, as far as I know, support regex

    0 讨论(0)
  • 2020-12-22 07:49
    $wordArray = str_split('string to array');
    
    0 讨论(0)
  • 2020-12-22 07:51

    in php you can use:

    split like

    Description

    array split ( string $pattern , string $string [, int $limit ] )
    

    Splits a string into array by regular expression.

    or

    implode

    <?php
    
    $array = array('lastname', 'email', 'phone');
    $comma_separated = implode(",", $array);
    
    echo $comma_separated; // lastname,email,phone
    
    ?> 
    
    0 讨论(0)
提交回复
热议问题