extract one item from an array?
Posted: Sun Feb 28, 2010 1:49 am
Hi,
I have an array that checks what page of a website the user is currently looking at. On each of my webpages i have this bit of code that gets the name of the page:
On a different php page i then have an array like this which just stores a list of the pages i want to check, this is then used as include file in the other pages.
I then check through the array to see what page the user is looking at using this code:
The problem I am having is if there are 6 pages in the array (the $deepLinkedPages array) then i get 6 footers on the page. If there are 2 pages in the array I get 2 footers. I think this is because I am using a foreach loop, but i've tried using while loop and cannot get this to work.
Where am I going wrong with this?
Thanks for any help.
I have an array that checks what page of a website the user is currently looking at. On each of my webpages i have this bit of code that gets the name of the page:
Code: Select all
$currentPage = basename($_SERVER['SCRIPT_NAME'])Code: Select all
$deepLinkedPages = array('about_us.php', 'index.php', 'contact_us.php');I then check through the array to see what page the user is looking at using this code:
Code: Select all
foreach ($deepLinkedPages as $page) {
if ($currentPage == $page) {
...display footer 1...
}else{
display footer 2
The problem I am having is if there are 6 pages in the array (the $deepLinkedPages array) then i get 6 footers on the page. If there are 2 pages in the array I get 2 footers. I think this is because I am using a foreach loop, but i've tried using while loop and cannot get this to work.
Where am I going wrong with this?
Thanks for any help.