Archived Boards and Threads... > Parham's PHP Tutorials
PHP Lesson 05 - arrays
Martje:
hey Andrew
thanks for your repley . no its not confusing I now html and I thought <br> had the same function in html as /n in php, but still i dont understand why I see ::)
1 2 3
instread of
1
2
3
in the example
$array = something();
foreach ($array as $element) {
echo $element . "\n";
}
function something() {
return array('1','2','3');
}
would print
Quote
1
2
3
it does not move the 2 or 3 to the next line on position 0.
it does put a space between 1 2 and 3
So I am still wondering what I am missing in this picture. forgive me but I am still a bit of a virgin on the php matters
writeto:
Maime:
I now understand your question much better. If you do a view source on the file generated you will see that it is
1
2
3
this is what he was talking about. You said you know HTML so you know that
<html>
<body>
1
2
3
</body>
</html>
will also generate 1 2 3. This is the output you are receiving. You still need to structure your output in HTML to get the appearance you want.
Andrew
[Unknown]:
Actually, \n is 13 and \r is 11. 9 is a tab, or \t.
Right... \n is just like hitting Enter on your keyboard. If you aren't doing it via html, it will show on separate lines. Here's an example:
--- Code: ---<?php
// Tell Internet Explorer that this is a text file not html.
header('Content-Type: text/plain');
// Store 1, 2, 3 in an array.
$arr = array(1, 2, 3);
// Print each value on its own line.
foreach ($arr as $val)
echo $val, "\n";
?>
--- End code ---
-[Unknown]
writeto:
Damn it I can never remember if \n represent 9 or 13... at least I remember that space is 32.
Andrew
dracomiconia:
Thanks...
I have a question:
Imagine I want to load and array with some indexes.
I am going to make a code, but I'm sure it is going bad:
--- Code: ---
//mysql query, which gives me some results. I charge the array:
$candidato = array(
'id' ,
'datos' => array(
'id_luchador' => $row["ID_REG"],
'fama' => round($row["fama"]/1000,0)+$key+1,
'pais' => $row["pais_escuela"]
),
);
//And finish the query. When I print_r:
print_r($candidato);
//This is the result:
Array ( [id] => 0 [datos] => Array ( [id_luchador] => 1 [fama] => 4 [pais] => Carsa ) )
//But when I make this:
echo "La escuela ".$candidato[0]['id_luchador']." tiene ".$candidato[0]['fama']." y es del pais ".$candidato[0]['pais'];
//The result is:
La escuela tiene y es del pais
--- End code ---
Where is it bad? And how can I arrange it?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version