PDA

View Full Version : (PHP)meaning of the code



ghusa
03-03-2009, 04:46 AM
while (list($k, $v) = each($_POST))
{
if(eregi("subs_",$k)) {
if ($set != "")
$set .= " , ";
$set .= " `$k`='$v'";
}
}

wat does this line of code means?
pls giv a solution.....

vangogh
03-03-2009, 10:42 AM
$_POST is an array that will contain values most likely passed from a form. They will contain a key and a value in the form key=value The first line

while (list($k, $v) = each($_POST))

is cycling through the $_POST array and setting the keys to $k and the values to $v

eregi is a function that handles regular expressions. The line

if(eregi("subs_",$k)) {

is looking in all the $k that were in $_POST and if one begins with the text subs_ continue. If it doesn't ignore the following code

if ($set != "")

$set is a variable that looks like it must be from some other part of the program. The line above is asking if $set is not equal to nothing. If $set already has some value continue to the following code

$set .= " , ";
$set .= " `$k`='$v'";

The two lines above are basically doing the same thing. Each is appending something new to the value of $set. The first line adds a space a comma and another space and the second line is adding the key and values that meet the requirements of the 'if' statements to it.

Essentially the code is looking at the $_POST array and if the keys start with 'subs_' it's adding both the key and value to the end of an already existing array.

Hope that makes sense.