From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Strings in PHP
- [Instructor] Strings are an integral part of your work in PHP and WordPress because you're going to be printing out a lot of information on the screen. It's worth taking a closer look at how strings work and some of the things to keep in mind. First is single versus double quotes. The main difference between single and double quotes is that any string in double quotes will be processed by PHP before it's outputted. That means, for example, any variables in strings with double quotes will become their literal value. Let's take a look at a simple example. You see, we have our age variable here. Age gets 34, and then we have an echo statement with double quotes. Joe is age years old. If we run this code, you'll see the result is Joe is 34 years old. But if we switch these quotes to single quotes, save and run it again, you'll see that the variable is printed out because it's taken as a string and not as a variable. To print a variable when using single quotes, we'll need to use what's…
Contents
-
-
-
What is PHP?2m 1s
-
(Locked)
Printing information3m 15s
-
(Locked)
What are variables?6m
-
(Locked)
Strings in PHP5m 57s
-
(Locked)
Using arrays7m 59s
-
Arithmetic operators and math in PHP6m 18s
-
(Locked)
Challenge: Perform mathematical operations and store it1m 41s
-
(Locked)
Solution: Perform mathematical operations and store it4m 25s
-
-
-
-
-