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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.