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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -