Archived Boards and Threads... > Parham's PHP Tutorials
PHP Lesson 05 - arrays
Parham:
--- Quote from: Aliencowfarm on August 30, 2003, 06:08:02 AM ---Parham i like these lessons :) i finally get what array is.. ( i had c++ at school.. the book wasn't that good niter was the teacher)
--- End quote ---
aww thank you :D:D
Spaceman-Spiff:
what is the proper syntax for returning an array from a function to another blank array var?
Parham:
you can simply just take the return value:
--- Code: ---$array = something();
foreach ($array as $element) {
echo $element . "\n";
}
function something() {
return array('1','2','3');
}
--- End code ---
would print
--- Quote ---1
2
3
--- End quote ---
you can also use the list() function on the return statement:
--- Code: ---list($var1,$var2,$var3) = something();
echo "$var1\n$var2\n$var3";
function something() {
return array('1','2','3');
}
--- End code ---
but you'd need to know how many elements are being returned :). The above example is just like returning an array and then assigning the first three values to variables.
Martje:
euhmm I used your example to see what it looks like
<?php
$array = something();
foreach ($array as $element) {
echo $element . "
";
}
function something() {
return array('1','2','3');
}
?>
but I did not get
1
2
3
I got
1 2 3
on my easyphp
the same for the other examples
is there something wrong with my configuration?
I am reading the examples and try to see the outcome in my head
and then verify it with the easy php server to see if it is the way that i thought.
maime
[edited]
might the right code be this
<?php
$array = something();
foreach ($array as $element) {
echo $element . "<br>\n";
}
function something() {
return array('1','2','3');
}
?>
he said proudly knowing that taking this lessons are not doing his brains in ;D :P
hehehe I feel having classes again.
but i still have not figured out the function of "\n" yet to me it does not act like a ENTER it acts like a SPACEBAR
writeto:
Maime:
I am going to attempt to clarify something for you. <br> is perfectly ok to use when generating HTML. However, the provided example was suppose to give you a general idea of the use of arrays. \n represent a carriage return, you will use \n when creating a file or formatting output. The use of echo in this example is as an i/o process in which you are printing $element to the screen, by including \n you are saying you want to place a carriage return (i believe it is ascii 9) that will move the cursor of the current display to the next line (where it will default to the 0 position. <br> is a horse of another color however. <br> is a symbolic reference in html. HTML stands for HyperText Markup Language. It is used to structure output for text and graphics... when your browser is interpretting <br> it is doing exactly the same thing as \n.
I tried to make this simple, if I confused you ignore it.
Andrew
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version