php中字符串转换成数组函数explode(),implode()
在php中数组与字符串相互转换最常用的方法就是使用explode(),implode()函数来转换了,今天我看一朋友问了一个这样的问题,下面我来整理一下分享给各位。
行看看这两个函数
implode 函数:
使用函数 implode 将数组转换为字符串
explode 函数:
使用函数 explode 将字符串转换成数组
例1.
今天在php论坛中看到以为朋友发了一个帖子请教php如何把字符串转换成数组;作为php程序员的新一第一反应是联想到explode(),implode()这两个函数。新一也是用里面的函数进行转换成数组的。
con[1]=28&selt[1]=1&con[2]=29&selt[2]=4&con[3]=26&selt[3]=4
&con[4]=30&selt[4]=2&con[5]=4&selt[5]=1&con[6]=11&con[7]=12
上面就是网友需要转换成PHP数组的字符串;下面也是新一提供PHP转换代码
代码如下 | 复制代码 |
$str = 'con[1]=28&selt[1]=1&con[2]=29&selt[2]=4&con[3]=26&selt[3]=4&con[4]=30&selt[4]=2&con[5]=4&selt[5]=1&con[6]=11&con[7]=12'; |
例2.
上面只支持一维数据,如果是二维或三维数据呢
代码如下 | 复制代码 |
$count = 0; if($count == 0){ if(empty($separator))$separator = $glue; return implode( $separator, $string ); |
例3.
将数组转成字符串存储及字符串取出转成数组(serialize & unserialize)
下面看一个实例:
代码如下 | 复制代码 |
// $Id: test3.php,v 1.0 2011-6-7 goba Exp $ --------str-------- |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
