Home  >  Article  >  Backend Development  >  What function can convert array to string in php

What function can convert array to string in php

青灯夜游
青灯夜游Original
2022-04-18 20:39:593484browse

The implode() function in php can convert an array into a string. implode() is used to convert a one-dimensional array into a string and return it. It accepts two parameters. The first parameter can set the connector, which can connect each element of the array together. It can be omitted and defaults to an empty character; syntax "implode("connector",array)".

What function can convert array to string in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The implode() function in php can convert an array into Convert to string.

implode() function can convert a one-dimensional array into a string and return a string composed of array elements. The syntax format is as follows:

implode(separator,array)
Parameter Description
separator Optional. Used to set a string, specify the content to be placed between array elements, and connect each element of the array together. Default is "" (empty string).
array Required. Arrays to be combined into strings.

Example 1: Set the first parameter of the implode() function

<?php
$arr = array(1,2,3,4,5,6,7,8,9);
$str = implode(",",$arr);
echo $str;
var_dump($str);

$str = implode("-",$arr);
echo $str;
var_dump($str);

$str = implode("::",$arr);
echo $str;
var_dump($str);
?>

What function can convert array to string in php

Example 2: Omit the first parameter

<?php
$arr = array(1,2,3,4,5,6,7,8,9);
$str = implode("",$arr);
echo $str;
var_dump($str);

$str = implode($arr);
echo $str;
var_dump($str);

?>

What function can convert array to string in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What function can convert array to string in php. 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