brosjr Posted July 20, 2012 Share Posted July 20, 2012 Hi everyone; The point is, I have a string to break, it contains data and a simple code (//&//) that is exploded to generate an array of values, like: M//&// Neves//&//salas 1 a 6//&// //&// Manual//&// //&// 70165900//&// Bras//&// Text Than I get the $explodedarray: Array ( [0] => M [1] => Neves [2] => salas 1 a 6 [3] => [4] => Manual [5] => [6] => 70165900 [7] => Bras [8] => Text) The problem is, a simple if comparison is not working: if($explodedarray[0] == 'M'){ echo 'yes'; }else{ echo 'no'; } It returns 'no'. Even if I try another comparison like: if($explodedarray[5] == ''){ echo 'yes'; }else{ echo 'no'; } It also returns 'no'. Any idea? Thankx Danilo Jr. Link to comment https://forums.phpfreaks.com/topic/266016-if-comparison-isnt-identifing-an-string-inside-an-array/ Share on other sites More sharing options...
Donald. Posted July 20, 2012 Share Posted July 20, 2012 Try echoing the array to see what the values in them are. Link to comment https://forums.phpfreaks.com/topic/266016-if-comparison-isnt-identifing-an-string-inside-an-array/#findComment-1363177 Share on other sites More sharing options...
Pikachu2000 Posted July 20, 2012 Share Posted July 20, 2012 There's whitespace in most of the array elements. $explodedarray = array_map( 'trim', $explodedarray ); Link to comment https://forums.phpfreaks.com/topic/266016-if-comparison-isnt-identifing-an-string-inside-an-array/#findComment-1363180 Share on other sites More sharing options...
brosjr Posted July 20, 2012 Author Share Posted July 20, 2012 Thank you Pikachu2000, It worked! Link to comment https://forums.phpfreaks.com/topic/266016-if-comparison-isnt-identifing-an-string-inside-an-array/#findComment-1363181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.