Concatenation with addition in it doesn't work as expected
Solution 1:
+
and .
have the same operator precedence, but are left associative. Means after the first concatenation:
'(' . (int)$data['event_id']
The string got added with your key, e.g.
"($data['event_id']" + $key
So the string gets converted into an integer in that numerical context and disappears. To solve this use parentheses ()
around your addition.
Solution 2:
This is happening because of the operator precedence. Try with -
$sql .= '('
. ((int)$data['event_id']) . ', '
. ($key + 1) . ', '
. ((int)$val['file_id']) . ', "'
. addslashes($val['url']) .
'"), ';