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

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.