M
Mike Barnard
On Wed, 12 Mar 2008 20:23:14 +0000 (UTC), BootNic
Hi.
I have been working through this. Google has been my friend along with
a post in comp.lang.php! It's neat and not too difficult to get my
head around as an absolute beginner. Thanks for taking the time to
work this out, even if it was only a minute or two.
Do you mind if I ask a question or two to clarify things?
Would it be normal to have HTML tags inside a PHP script when they
aren't part of an echo statement or similar?
OK, I have this. An array of 6 items called "menu", the first value
being the content of the array and the second it's key, [reference or
address].
This gets the value "/test/index.php" on my new install of WAMP5. I
have the www folder in WAMP5 and a subfolder called test. In this is
index.php.
Go through a for loop, looking in $menu and assigning the content of
the array to the variable $key (which increases each iteration). I
think. More google.
Write span?
OK, slight confusion here. === means is the value AND the type a
match. So, on the first loop $key contains "/index.php", $location
contains "/test/index.php". They are different so it should fail.
Write a? What?
End the foreach loop.
As the value of $location has the /test/ bit in it, and none of the
entries in the array have this, how can it ever be true?
Hi.
I have been working through this. Google has been my friend along with
a post in comp.lang.php! It's neat and not too difficult to get my
head around as an absolute beginner. Thanks for taking the time to
work this out, even if it was only a minute or two.
Do you mind if I ask a question or two to clarify things?
<ul class="menu">
Would it be normal to have HTML tags inside a PHP script when they
aren't part of an echo statement or similar?
<?php
#menu array
$menu = array('/index.php' => 'Home',
'/law.php' => 'The Law',
'/diy.php' => 'How to DIY',
'/hire.php' => 'Hire Me',
'/links.php' => 'Links',
'/contact.php' => 'Contact');
OK, I have this. An array of 6 items called "menu", the first value
being the content of the array and the second it's key, [reference or
address].
#current page
$location = $_SERVER["SCRIPT_NAME"];
This gets the value "/test/index.php" on my new install of WAMP5. I
have the www folder in WAMP5 and a subfolder called test. In this is
index.php.
#build menu items
foreach ($menu as $key => $value)
Go through a for loop, looking in $menu and assigning the content of
the array to the variable $key (which increases each iteration). I
think. More google.
{
echo " <li>\n";
Print said:#if current page write span
Write span?
if ($key === $location)
OK, slight confusion here. === means is the value AND the type a
match. So, on the first loop $key contains "/index.php", $location
contains "/test/index.php". They are different so it should fail.
{
echo " <span>$value</span>\n";
}
If it was a match it would add the above to the said:#else write a
Write a? What?
else
{
echo " <a href=\"$key\">$value</a>\n";
}
Create the statement said:echo " </li>\n";
Finish it off with said:
End the foreach loop.
As the value of $location has the /test/ bit in it, and none of the
entries in the array have this, how can it ever be true?