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

What function can convert array to string in php

青灯夜游
Release: 2023-03-15 18:32:02
Original
3503 people have browsed it

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)
Copy after login
ParameterDescription
separatorOptional. 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).
arrayRequired. 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);
?>
Copy after login

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);

?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template