I have the following array to add to the database.
$arr = array("a'a","b'b","c'c");
To escape the single quotes before adding to database I use this for loop
for ($i=0; $i < count($arr); $i++) {
$arr[$i] = addslashes($arr[$i]);
}
And it works just fine. But if the original array is changed to this:
$arr = array("first"=>"a'a","b'b","c'c");
then I get the following error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 150994944 bytes) in /home/filepath/file.php on line 12
I'm not sure why I get this error when the array has a custom key of "first". I wouldn't get this error if I manually use addslashes to each array value but whenever I put it in a for loop I get the error.
Does anyone have a work around for applying addslashes to each array value? I've tried mysqli_real_escape_string instead of addslashes but I got the same error.