标签:数组 php字符串 图片 打印 shang span inf family bsp
一 字符串转数组 explode方法
<?php // 字符串转数组 $string = "Hello World love Shanghai"; $arr1 = explode(" ", $string); print_r($arr1);
打印结果
Array ( [0] => Hello [1] => World [2] => love [3] => Shanghai )
用于分割字符串的函数有两个,这里要特别区分:一个是 explode方法 另一个是str_split
$string="hello world"; $arr1=str_split($string,2); print_r($arr1)
打印结果
Array ( [0] => he [1] => ll [2] => o [3] => wo [4] => rl [5] => d )
二 数组转换为字符串 implode
$arr2= array(‘Hello‘,‘World!‘,‘hh‘,‘oo‘); $str = implode(" ",$arr2); print_r($str);
打印结果
Hello World! hh oo
标签:数组 php字符串 图片 打印 shang span inf family bsp
原文地址:https://www.cnblogs.com/dumenglong/p/11496321.html