Results 1 to 2 of 2

Thread: (PHP)meaning of the code

  1. #1

    Default (PHP)meaning of the code

    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.....

  2. #2
    Post Impressionist
    Array
    vangogh's Avatar

    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    15,059
    Blog Entries
    1

    Default

    $_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.
    l Join me as I share my creative process and journey as a writer | StevenBradley.me
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Get my book about Design Fundamentals

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •