Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ' and " in PHP? [duplicate]

Tags:

syntax

php

Possible Duplicate:
PHP: different quotes?

Simple question:

What is the difference between ' and " in php? When should I use either?

like image 533
johnnietheblack Avatar asked Sep 09 '09 22:09

johnnietheblack


People also ask

Whats the difference between -> and :: in PHP?

They are for different function types. -> is always used on an object for static and non-static methods (though I don't think it's good practice use -> for static methods). :: is only used for static methods and can be used on objects (as of PHP 5.3) and more importantly classes.

What is the difference between -> and =>?

Conclusion. The two operators, => and -> may look similar but are totally different in their usage. => is referred to as double arrow operator. It is an assignment operator used in associative arrays to assign values to the key-value pairs when creating arrays.

What is the difference between & and && in PHP?

Introduction to the PHP AND operator The && and and operators return the same result. The only difference between the && and and operators are their precedences. The and operator has higher precedence than the && operator.

What is the difference between echo and print in PHP?

They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print .


1 Answers

Basically, single-quoted strings are plain text with virtually no special case whereas double-quoted strings have variable interpolation (e.g. echo "Hello $username";) as well as escaped sequences such as "\n" (newline.)

You can learn more about strings in PHP's manual.

like image 76
Josh Davis Avatar answered Oct 11 '22 14:10

Josh Davis