Jump to content

Stumped on loop if statement..


Scooby08

Recommended Posts

If I have code that looks something like this:

 

<?php
$t = array('one','two','three','_four','_five','_six');
$u = 'five';
foreach ($t as $v) {
if (substr($v,0,1) != '_') { // if begins with an underscore, remove it, unless it is equal to _$u
	echo $v.'<br />';
}
}
?>

 

I am trying to take out all array items that begin with an underscore except the one that is equal to this..

 

_five

 

something like

 

$v == '_'.$u

 

So what should be echoed is this:

 

one

two

three

_five

 

Is there any way to do this with only an if, and not an if/else??

 

Thanks..

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.