[thelist] PHP & CSS (Two Part Question)
Burhan Khalid
burhankhalid at members.evolt.org
Wed May 1 19:50:01 CDT 2002
[ snip ]
You seem to indicate you need to have the
>numerical key, but why?
[ /snip ]
I was going to use the key as a limiter. If say, the current page is in the
4th spot on the array, then the key would be 5. Using this information, I
can build the navigation so that it doesn't include everything, and just
stops at 4.
Lets say the current page is NavTest7, and using the following array
structure :
[ 0 ] = "index.php"
....
[ 6 ] = "NavTest7.php"
Then (in my current setup, I have two arrays), I would step through the
other array :
[ 0 ] = "Home Page"
...
[ 6 ] = "Navigation Test Page 7"
And build my trail, which would be :
Home > ... > Navigation Test Page 7
>You can iterate over the array--and have the numerical index(0), the
>value ("Home Page"), and the key ("index.php") available to you--using
>something like the following:
>
> // for each navigation element
> while(list($value,$key) = each($navigation));
> {
> // insert whatever actions you need to do here
> echo "<a href='$key'>$value</a><br />";
> }
Two questions, isn't that list($value, $key) supposed to be list($key,
$value), or does
it not matter? How would I get the numerical index from that list thing?
Wouldn't that just print a bunch of links from my array? The only way I can
see that happening is if I stick a counter in there, which iterates on
every instance of the loop. Which makes me think that I would have to use a
break in there somewhere, with an if(), so that it doesn't just print the
whole trail. What do you think?
>If, for some reason you need to have both the numeric (implied) and
>string (explicit) keys than use the array_keys function. [ see also
>http://www.php.net/manual/en/function.array-keys.php ] This requires
>that you are using PHP 4 and you had better be.
>
> // define the navigation
> $navigation = array ("index.php" => "Home Page", "contact.php" =>
>"Contact Us");
>
> // build an array to better define our keys
> $keys = array_keys($navigation);
>
> // now for each navigation element
> while(list($num_key,$str_key) = each($keys));
> {
> // insert whatever actions you need to do here
> echo "<a href='$str_key'>($num_key) $navigation[$num_key]</a><br
>/>";
> }
Hmm...looks promising, I'm going to give it a shot.
More information about the thelist
mailing list