Tuesday, June 12, 2012

PHP in_array not working as expected after split or explode

Error

Testing the existance of a variable using "in_array" function returning false although you can see the value in the array using print_r ??


Solution

For me this problem was due to using

split("\n",$text) instead of split("\r|\n",$text)

The first one leaves a "\r" with every value in the array, that was tricky :)

I ended up using the following implementation

$excludesArray = preg_split("/ |\n|\r\n/",$excludesText);


No comments:

Post a Comment