If someone wants to add slashes to multidimensional array directly, can use recursive (pass-by-reference) function like this:
<?php
function slashit(&$aray, $db_link)
{
foreach ($aray as $key => &$value)
if(is_array($value)) slashit($value, $link);
else $aray[$key] = mysql_real_escape_string($value, $db_link);
}
$fruits = array (
"fruits" => array("a" => "or'ange", "b" => "ban'ana", "c" => "apple'"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("fir'st", 5 => "sec'ond", "thir'd"),
"odma" => "jugo'slavija"
);
slashit($fruits, $dbLink);
echo "<pre>"; print_r($fruits); echo "</pre>";
?>
// Output:
Array
(
[fruits] => Array
(
[a] => or\'ange
[b] => ban\'ana
[c] => apple\'
)
[numbers] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
[holes] => Array
(
[0] => fir\'st
[5] => sec\'ond
[6] => thir\'d
)
[odma] => jugo\'slavija
)