Scooby08 Posted August 13, 2010 Share Posted August 13, 2010 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 https://forums.phpfreaks.com/topic/210611-stumped-on-loop-if-statement/ Share on other sites More sharing options...
Alex Posted August 13, 2010 Share Posted August 13, 2010 if (substr($v,0,1) != '_' || $v == '_' . $u) { Link to comment https://forums.phpfreaks.com/topic/210611-stumped-on-loop-if-statement/#findComment-1098735 Share on other sites More sharing options...
Scooby08 Posted August 13, 2010 Author Share Posted August 13, 2010 Oh my goodness... Thanks a bunch AlexWD! Link to comment https://forums.phpfreaks.com/topic/210611-stumped-on-loop-if-statement/#findComment-1098737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.