kernelgpf Posted February 1, 2009 Share Posted February 1, 2009 Alright, my script takes a list from a database: apple | red | juicy, orange | orange | fleshy, grapefruit | pink | fleshy explodes between the commas making apple | red | juicy orange | orange | fleshy grapefruit | pink | fleshy and then runs a foreach on the exploded parts, and further explodes it between the bar things ( | ). So it then becomes apple | red | juicy [0] apple [1] red [2] juicy orange | orange | fleshy [0] orange [1] orange [2] fleshy grapefruit | pink | fleshy [0] grapefruit [1] pink [2] fleshy beautiful. then I take the first part of the second explosion. [possible values are apple, orange, or grapefruit], and try to match it up with the variable "$fruit". I was running into problems, so I made it print out the first part of the second explosion and made it print out $fruit next to it. If the two matched up, "MATCH" should print. now, MATCH ONLY prints when "apple" (or $fruit) is FIRST in the first explosion. So my script works if $row[biglistoffruit] equals "apple | red | juicy, orange | orange | fleshy" but not "orange | orange | fleshy, red | juicy | apple." I need it to work regardless of where it is in the first explosion. Script: $fruit="apple"; $fruitarray = explode(",", $row[biglistoffruit]); foreach ($fruitarray as $value){ print "$value<br>"; //check if this part of the array has the fruit $fruitinfo=explode(" | ",$value); print "if $fruitinfo[0] equals $fruit<p>"; if($fruitinfo[0] == $fruit){ //if this matches print " - MATCH!<p>"; } } Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 2, 2009 Share Posted February 2, 2009 Try <?php if(trim($fruitinfo[0]) == $fruit){ print " - MATCH!<p>"; } if that works, you know your problem -- evil whitespace If that has nothing to do with your problem, then it's because I totally don't understand what your question is. Quote Link to comment Share on other sites More sharing options...
kernelgpf Posted February 2, 2009 Author Share Posted February 2, 2009 Holy crap. I can't believe it was that simple to solve, I've been working on this thing for HOURS! You rock. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.