Home > Backend Development > PHP Tutorial > php遍历字符串每一个字符转换成数组。

php遍历字符串每一个字符转换成数组。

WBOY
Release: 2016-06-23 13:34:34
Original
1745 people have browsed it

php:遍历字符串每一个字符,追加给新数组。

<?php/*   $str[$i]:字符串变量名+下标可以取值到对应下标的字符串的值。   explode(separator,string,limit)可以以固定字符为断点转换成数组   ru*/	$str = "abcde";//被遍历的字符串	$arr = array();//定义要输出的数组	for($i=0;$i<strlen($str);$i++){//遍历字符串追加给数组		$arr[] = $str[$i];	}	print_r($arr);//查看结果?>
Copy after login


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