Hi, I keep on seeing these characters in PHP, but I have no idea what they do. I also can't look them up on Google because I don't know what they're called. Anyway, the 2 expressions (or whatever they are) are: %s example: sprintf("INSERT INTO products (`name`, `description`, `user_id`) VALUES ('%s', '%s', %d)", mysql_real_escape_string($product_name, $link), mysql_real_escape_string($product_description, $link), => example: foreach($_GET as $k=>$v) Will anyone fill me in on what these are, what they do or what they're called? Thanks a lot!
=> is used for arrays, like $foo = array('1' => "Apples", '2' => "Oranges") ; accessed like $foo['1'] ; the foreach is taking all the GET parameters and processing them as keys ($k) and values ($v). http://us3.php.net/manual/en/language.types.array.php covered at that url. sprintf at php.net (http://us3.php.net/manual/en/function.sprintf.php )
sprintf is a function that formats a string using other variables. the first parameter is the format and the other parameters are all the variables. the %s and %d (there are more) are placeholders to a specific type of variable. for example, if you put %s, the variable is treated as string. %d is treated as integer. so sprintf("my name is %s and i'm %d years old", 'yo' . 'av', 10 + 15) will print "my name is yoav and i'm 25 years old" => is used to associate a key to a value in an array PHP's arrays are all associative. in shallowink's example, '1' is associated to "Apples" and '2' to "Oranges".
Hey guys, One more... can someone post a page that will explain this: -> example: $fields[$this->name.'.'.$field] = $value; Thanks again! -Dan
The dot is the concatenation operator. It smushes two or more strings together into one. In this case there are three strings lined up for besmushal: $this->name, a period, and $field. So if $this->name == 'tomato' and $field == 'sandwich', then it's effectively doing: $fields['tomato.sandwich'] = $value;
Thanks SmallPotatoes. I'm more concerned about this part: $this->name I'm not sure what the -> does. It looks like it returns array values or something... ?
$this refers to the current object, and -> is how you reference an object property. If this terminology doesn't make sense, you'd be best off reading about PHP object-oriented programming at http://www.php.net/manual/en/language.oop5.basic.php