search
HomeheadlinesPHP string function (3): conversion between string and array

Recommended manual:php complete self-study manual

* 1.str_split($str,$length=1), according to the number of characters, Split the string into an array, the default is 1

* 2.explode($delimiter,$str,$num): Split the string into an array according to the delimiter, the number of array elements can be specified

* 3.implode($glue, $str): Assemble the one-dimensional array into a string according to the delimiter, separated by spaces by default

echo &#39;<pre class="brush:php;toolbar:false">&#39;;
$str = &#39;html,css,jquery,php,mysql,thinkphp&#39;;
echo &#39;<p>原始字符串:&#39;.$str.&#39;</p>&#39;;

1.str_split($str,$length=1) Split the string into an array according to the number of characters, the default is 1

print_r(str_split($str)); //默认一个字符转为数组中的一个元素
print_r(str_split($str,5)); //5个一组进行转换

2.explode($delimiter,$str,$num): Split the string into an array according to the delimiter, you can Specify the number of array elements

print_r(explode(&#39;,&#39;,$str)); //用&#39;,&#39;号进行分割字符串
print_r(explode(&#39;,&#39;,$str,5)); //指定数组必须是5个元素,最后一个元素保存全部剩余数据

3.implode($glue, $str): Assemble the one-dimensional array into a string according to the delimiter, separated by spaces by default

$arr2 = explode(&#39;,&#39;, $str);
echo implode(&#39; &#39;, $arr2), &#39;<br>&#39;; //用空格分隔
echo implode(&#39;,&#39;,$arr2), &#39;<br>&#39;; //用,分隔
echo implode(&#39;--&#39;,$arr2), &#39;<br>&#39;; //用--分隔
Recommended related articles:
1.Convert PHP arrays and strings to each other
2.Detailed explanation of the two methods of converting PHP arrays to strings [Video attached]
3.Explanation of PHP string to array and array to string functions
Related video recommendations:
1.Dugu Jiujian (4)_PHP video tutorial
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools