-Hi, I have this example of a php function from a textbook I鈥檓 using and have a general n00by question:
In the code:
<?php
function printBR($txt)
{
echo $txt."
";
}
printBR("This is a line");
printBR("This is a new line");
printBR("This is yet another line");
?>
Could $txt be referred to as an array?function printBR($i){
if(is_array($i)){
$c = count($i);
for($x=0;$x<$c;++$x){
echo $i[$x] . '<b' . 'r />'; // Yahoo Doesn't properly display br tags
}
}else{
echo $i . '<b' . 'r />';
}
}
Keep in mind though, that you won't see the keys to the array. If you want to see them, then substitute in:
echo '<pre>';
print_r($i);
echo '</pre>';
Cheers,
Gitlez
Directly echoing an array won't give you the results you want.
You would need to loop through the array and print each element:
$num = count($txt);
for ($i=0; $i<$num; $i++) {
echo $txt[$i] . "\n";
}
没有评论:
发表评论