Home > Backend Development > PHP Tutorial > 如何替换数组里面的键值。

如何替换数组里面的键值。

WBOY
Release: 2016-06-23 14:38:19
Original
1557 people have browsed it

本帖最后由 qq914260102 于 2013-11-28 15:03:47 编辑

比如我一个一个数组,$rs[]=$row["test"];
这个数组是(0,0,0,1,2,1,0,2,1,0)
我想把里面的
0替换成“是”,
1替换成“否”;
2替换成“未知”,
然后还是一个数组。。。

(是,是,是,否,未知,否,是,未知,否,是)

回复讨论(解决方案)

$a = array(0,0,0,1,2,1,0,2,1,0);
$b = array();
for($i=0;$i $b[$i] = ($a[$i]==0)?"是":($a[$i]==1?"否":"未知");
}
print_r($b);
////////////////////////////
Array ( [0] => 是 [1] => 是 [2] => 是 [3] => 否 [4] => 未知 [5] => 否 [6] => 是 [7] => 未知 [8] => 否 [9] => 是 ) 

感谢。

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