如何打开以下数组
$p = array('1' => 'a', '2' => 'b', '3' => 'c');
进入以下输出?请注意,每个数组元素都在单独的行上:
1:a
2:b
3:c
您正在寻找基本的 for-each 构造:
$p = array('1' => 'a', '2' => 'b', '3' => 'c');
foreach($p as $key => $value) {
echo $key.":".$value."\n";
}
var $colon_separated = array();
foreach ($a as $key => $value) {
$colon_separated[] = "$key:$value";
}
$result = implode("\n", $colon_separated);