Jump to content

Check if in array but not include some values in the array


Ricky55

Recommended Posts

I have an array created to control the down states of the my buttons in my navigation. Which is working well. This array will have quite a few strings in it before I'm done.

 

I then want to conditionally load a CSS file for all the files in that array with the exception of two, is this possible?

 

In plain in english I want to say If in array apart from these values then load my css file.

 

My array (will have more values when complete)

 

$otherTitles = array('Product Selector', 'Avon Range', 'Knightsbridge Range', 'Kingston Range' );

 

My code to load a css file

 

<?php if (in_array($title, $otherTitles)) { ?>
<link rel="stylesheet" type="text/css" href="homepage.css"/>
<?php } ?>

 

I want all titles in the otherTitles array to get this CSS file apart from two Product Selector and Avon Range.

 

Thanks

 

Richard

 

Link to comment
Share on other sites

If I understand what you're asking, you could just use a nested if statement. Something like:

 

<?php if (in_array($title, $otherTitles)): ?>
    <?php if ($title != 'Product Selector' && $title != 'Avon Range'): ?>
	<link rel="stylesheet" type="text/css" href="homepage.css"/>
<?php endif; ?>
<?php endif; ?>

Link to comment
Share on other sites

That's exactly what I meant thanks very much. Its only a small CSS anyway but not point in loading it if it doesn't need to be loaded.

 

Didn't know you could do nested statements like this (obviously)

 

Thanks very much!

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.