Jeffery Vaska
I wish I had known these 10 simple things the day I started working with PHP. This article is part II in the this series and is intended for newbies. The previous article is located here.
Tip 6: Single and double quotes
Single and double quotes confused me for some time and it really should not have. I see this quite often in the forum as well. It's very easy to understand that double quotes allow php to parse and single quotes do not. Here are some examples:
$var = $value; // ok
$var = "$value"; // ok, but double quotes are not necessary
$var = '$value'; // will not work (single quotes will not allow parsing)
('.' the period adds/connects variables, functions, etc. together.
Oftentimes programmers will leave spaces around the ' . ' to make
things easier to read.)
$var = 'This is the ' . $value . ' of things.'; // ok - preferred
technique
$var = "This is the $value of things."; // ok, but harder to read/debug
$var = 'This is the $value of things.'; // will not parse $value
$var = This is the $value of things.; // error
$var = $array['name']; // ok, generally the preferred technique
$var = $array["name"]; // ok, but why use double quotes if they are not
necessary?
$var = "$array[name]"; // ok, but harder to read/debug - poor coding
style
$var = 'Name: ' . $array['name']; // ok - preferred technique
$var = "Name: $array[name]"; // ok, but harder to read/debug - poor
coding style
$var = "Name: $array["name"]"; // error
$var = "Name: $array['name']"; // error
exampleFunction($value); // ok
exampleFunction("$value"); // ok, but double quotes are not necessary
exampleFunction('$value'); // will not parse $value
Subscribe to:
Post Comments (Atom)
TIPS YOUTUBER PEMULA MENINGKATKAN VIEWER
Oke kali saya akan membahas tentang Tips Youtubers Pemula untuk meningkatkan Viewer dan Popularitas Chanel Youtube Kita. Sebagus apapun vide...
-
If a method can be static, declare it static. Speed improvement is by a factor of 4. echo is faster than print . Use echo's multiple pa...
-
Your web site should be easy to read Your web site should be easy to navigate Your web site should be easy to find Your web page layout and ...
-
Banyak orang menghabiskan tak sedikit uang untuk urusan pembuatan dan desain website, namun kemudian mendapati bahwa mereka hanya memiliki s...
No comments:
Post a Comment