Jump to content

How to check an array for a matching string and return true - Newbie help


spryce

Recommended Posts

I have a web server which contains a public site and a private site. I want to be able to test for public or private using the page title and return the appropriate header which contains a different banner, css etc.

 

Firstly - the syntax below seems to be incorrect because it doesnt work correctly.

More importantly how do I add all the values to an array and than iterate through it to check for a matching page title?

 

public function publicSite() {
	if ($this->getTitle()== 'Home' || 'About Us'||'Registration' || 'Sitemap' || 'Contact Us' || 'Useful Links' || 'Feedback') {
		return true;
	}
	return false;
}

Then later on I would have:

	if ($this->publicSite()) {
		require($ROOT.'interface/pages/publicheader.php'); 
	}
	else {
		require($ROOT.'interface/pages/privateheader.php'); 
	}

 

Thanks heaps!

Link to comment
Share on other sites

try this

 

public function publicSite() {
	if ($this->getTitle()== 'Home' || $this->getTitle()== 'About Us'|| $this->getTitle()=='Registration' || $this->getTitle()== 'Sitemap' || $this->getTitle()=='Contact Us' ||$this->getTitle()== 'Useful Links' || $this->getTitle()=='Feedback') {
		return true;
	}
	return false;
}

Link to comment
Share on other sites

kney's reply is syntactically correct, but a more appropriate way will be this:-

 

$titles = array('Home', 'About Us', 'Registration', 'Sitemap', 'Contact Us', 'Useful Links', 'Feedback');

if (in_array($this->getTitle(), $titles))
{
    $this->publicSite() = true;
}

else
{
    $this->publicSite() = false;
}

Link to comment
Share on other sites

kney's reply is syntactically correct, but a more appropriate way will be this:-

 

$titles = array('Home', 'About Us', 'Registration', 'Sitemap', 'Contact Us', 'Useful Links', 'Feedback');

if (in_array($this->getTitle(), $titles))
{
    $this->publicSite() = true;
}

else
{
    $this->publicSite() = false;
}

 

Thanks :)..

I didn't know how to use arrays anymore, that's why the 'crappy' reply :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.