m.jay.victor
-
Posts
4 -
Joined
-
Last visited
Never
Posts posted by m.jay.victor
-
-
thanks again...
any advice for a beginner? Good tutorial sites, text editors etc? I downloaded zendstudio IDE trial but that seems like I am bringing a nuclear weapon to a knife fight.
-
to learn how.
I started learning PHP about 2 days ago and I am following that tutorial I linked earlier. The next logical step for me was to see if I could nest the arrays.
Anyhow, I noticed part of what you fixed was the way I defined the artist array.
from
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands");
to
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', $morebands);
What i don't understand is why this was necessary. I know it was, because the code would output the word "array" on the last line if you did not remove the quotes. Can you explain why this happened though?
-
<html>
<head></head>
<body>
My favourite bands are:
<ul>
<?php
// define arrays
$morebands = array('Desturbed', 'Anthrax');
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands");
// loop over it
// print array elements
foreach ($artists as $a) {
if ($a != 'Array'){
echo '<li>'.$a;
}
Else {
foreach ("${$a}" as $b){
echo '<li>'.$b;
}
}
}
?>
</ul>
</body>
</html>
I can not figure out why this will not work:(
I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well.
I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so).
right now I am working on
http://devzone.zend.com/node/view/id/635
anyhow thanks for any help!
Simple Script help
in PHP Coding Help
Posted
Thank you Abra, I was however trying to extend my knowledge of foreach, and how I may nest arrays. Your way is by far functionally better of course, but I am just trying to extend what I got from that one lesson.
You did however teach me that it was possible to merge arrays though:)
Wich brings me to...
Would that have not been simpler?