Home >Backend Development >PHP Tutorial >PHP的explode怎么才能做到这样子?

PHP的explode怎么才能做到这样子?

WBOY
WBOYOriginal
2016-06-23 14:03:281073browse

$userdomain="1,2,3,4,5";

$piece = explode(",", $userdomain);
$name0=$piece[0];
$name1=$piece[1];
$name2=$piece[2];
$name3=$piece[3];
$name4=$piece[4];

echo "$name0 $name1 $name2 $name3 $name4";

这样输出为12345

怎么写,可以输出 54321?

当然 得保持echo "$name0 $name1 $name2 $name3 $name4";
而不是echo "$name4 $name3 $name2 $name1 $name0";

就是怎么样让explode倒序输出?


回复讨论(解决方案)

先explode 再array_reverse反正数组

先explode 再array_reverse反正数组

不会呀,能帮写出吗?

echo "$name0 $name1 $name2 $name3 $name4";

这样输出为12345

$piece = array_reverse(explode(",", $userdomain));

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