mysql - Need explanation of this php code $variable = array(); -
excuse me possibly stupid question, need understand how code works. searched google , no understandable answer
here code:
$data = array_merge($one,$two); $sql = "insert msql_table (one, two) values "; $insertquery = array(); $insertdata = array(); foreach ($_post['one'] $i => $one) { $insertquery[] = '(?, ?)'; $insertdata[] = $one; $insertdata[] = $_post['two'][$i]; } if (!empty($insertquery)) { $sql .= implode(', ', $insertquery); $stmt = $db->prepare($sql); $stmt->execute($insertdata); }
can not understand code:
$insertquery = array(); $insertdata = array();
usual code "insert msql_table (one, two) values (?, ?)";
i understand values
$insertquery = array();
, array()
defined latter.... big mess in head.
may link information code (explanation of code)? want understand these 2 lines do
those 2 lines initialize variable, , creates empty array. way, when data inserted array later, php won't complain (depending on error_reporting) variable doesn't exist.
here's link http://php.net/manual/en/language.variables.basics.php
Comments
Post a Comment