php - What is the purpose of strlen($query)-2; -
i got code google , fulfills requirement, don't understand meaning of line:
substr($query,0,strlen($query)-2)
could explain me?
<?php function insert($tablename, $parameter_order, $values) { $query = "insert $tablename ("; foreach($parameter_order $po) { $query .= $po.', '; } $query = substr($query,0,strlen($query)-2).') values ('; foreach($values $v) { $query .= "'$v', "; } $query = substr($query,0,strlen($query)-2).');'; return $this->makequery($query); } ?>
this functions exactly:
substr()
used generate sub-string of specified length string.
strlen()
return length of provided string.
code substr($query,0,strlen($query)-2)
removes comma , space foreach
loop.
Comments
Post a Comment