![]() ![]() After this has been executed, the contents of $y is "Alphabet Soup for lunch." When you want an assignment statement to mix literal strings with PHP variables, you must use double quotes. This is the preferred way to write the expression avoid unnecessary quotes. Since there is no mix of literal string values and variable values, PHP will also allow you to write this without any quotes. First, Alphabet Soup is assigned to $x, then $x is assigned to $y. This code example is functionally identical to the immediate prior example. Double quotes allow variable substitution single quotes do not. When you use variables (as opposed to literal strings) in PHP, there are different meanings for single and double quotes. $x = 'Alphabet Soup' $y = "Alphabet Soup" Note that one uses single quotes and the other uses double quotes. If you want to assign these literal string values to PHP variables, you must put quotes around them in the assignment statement. ![]() You can probably figure out the lengths of the other two strings. The first string is the single capital letter "A" and it has a length of one character. The code snippet below has examples of perfectly valid strings. We will show some examples and explanation below.Ī string is nothing more than a few characters strung together. ![]() If it doesn't all "click" at first, don't be too concerned. You need to understand the terms "variable" and "string" as they are used in the context of computer programming. And it got me thinking, "How can we explain the rules for quotation marks?" For better or worse, PHP has so many rules! This article tries to answer the questions.įirst, some mandatory reading. This question seems to come up a lot for developers who are new to PHP. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |