I have the following code
$checkarray = unserialize(file_get_contents('serialized.txt'));
var_dump($checkarray);
foreach($checkarray as $_index => $_image )
{
echo strval($_index)." = ".var_dump($_image)."<br>";
}
var_dump(array_search('pirates_of_love_and_kingdoms.jpg',$checkarray));
var_dump(in_array('pirates_of_love_and_kingdoms.jpg',$checkarray));
the contents of 'serialized.txt' can be found here (http://textuploader.com link, not a download link, will need to copy and paste into new file if you want to use it)
the first var_dump output the array however because i have xdebug not the entire array is outputted, i'm not looking to get this fixed, it just confirms that the file was imported and unserialize correctly, the loop outputs everything in the array confirming that every value is a string (thanks to xdebug), the final 2 var_dumps are to output the results of the functions.
when i run my code, both var_dumps output false, however if i use the browser to search for the text i do find it so i know it's in the array.
I know that array_search returns the key in the array if the needle is found while in_array returns true if the needle is found and both will return false if the needle can't be found, however i do not get how neither can find it when i can confirm it's outputted in the loop and in my serialized.txt file at the same index as what is specified in the file.
i have already checked the basics, white spaces, new lines, casing in both what is outputted on the screen and in the file, can anyone explain to me what i have done wrong?
file()to read your text file into an array instead offile_get_contents()file_get_contents()because it gets it as a string and not an array, if you looked in the text file i uploaded you'll see that it's a serialized string, what i search for in the 2 functions is identical to what i search for using the browser and in notepad++