Learn PHP Variables

Learn about PHP variables and the string and number data types.

Start[missing "en.views.course_landing_page.learn-php.course_illustration" translation]
Chevron Left Icon
PHP Strings and Variables
Lesson 1 of 2
Chevron Right Icon
  1. 1

    illustration of string In everyday conversation, we use the word data to refer to any sort of informati…

  2. 2

    We use quotation marks to indicate the start and end of a string. The quotation marks tell the computer that we want everything inside them to be treated as a single piece of data. But how do we in…

  3. 3

    It can be useful to combine two strings together. This process is called string concatenation, and we can use the concatenation operator ( […] ) to do this. An operator is a character that …

  4. 4

    Let’s say I have a really long string in my program, and I’m going to need to use it multiple times. Do I have to type the string out every time I need to use it? The answer is “no”. Variables are …

  5. 5

    Let’s look at an example of creating a variable: […] In the code above, we’re actually doing two things with a single statement: we’re declaring a new variable by giving it the name […] ….

  6. 6

    Once we’ve declared a variable and assigned a value to it, we can use it as many times as we want. We refer to a variable by using the dollar sign followed by the variable’s name. […] Except…

  7. 7

    In the last exercise, we saw how concatenating a number of strings and string variables got annoying. There’s an easier way! PHP strings allow us to place variables directly into double quoted st…

  8. 8

    The word variable comes from the latin variāre which means “to make changeable.” This is an apt name because the value assigned to a variable can change. ![gif of reassignment](https://s3.amazona

  9. 9

    We can assign and reassign variables to the values that result from operations: […] During assignment, the computer will first evaluate everything to the right of the assignment operator and r…

  10. 10

    When we create a variable assigned to another variable, the computer finds a new space in memory which it associates with the left operand, and it stores a copy of the right operand’s value there. …

  11. 11

    Awesome work! We’ve covered a lot of material in this lesson, so let’s review: - Strings are collections of text that the computer treats as a single piece of data. - A string can be any length an…

  1. 1

    Numbers and arithmetic operations are a fundamental part of programming. In this lesson, we’ll learn how to use and manipulate numbers in PHP. PHP has two number data types. The integer data ty…

  2. 2

    PHP provides several operators we can use on numbers. Let’s start with two that are likely familiar: the addition ( […] ) and subtraction ( […] ) operators: […] Most of the time, we don’t …

  3. 3

    We can use number operators on variables that hold number values: […] Let’s look at another example of performing operations with number variables: […] In the code above, we created the var…

  4. 4

    PHP also gives us operators for performing multiplication ( […] ) and division ( […] ). […] Like with addition and subtraction, when we perform multiplication or division, the computer wil…

  5. 5

    PHP give us an operator for raising a number to the power of another number: the exponentiation operator ( […] ). For example, we can square a number by raising it to the power of 2: […] We…

  6. 6

    PHP also provides an operator that might be less familiar: modulo ( […] ). The modulo operator returns the remainder after the left operand is divided by the right operand. […] In the co…

  7. 7

    We can chain multiple operations together to get a single result: […] You might have learned about operations having an order of precedence in a math class. This means that operations in a chai…

  8. 8

    One common task when manipulating number variables is to reassign them to their old value with some operation performed on it. […] This is such a common task that PHP provides a shorter synta…

  9. 9

    Great job! In this lesson, we learned all about using numbers in PHP. Let’s review what we covered: - PHP has two number data types: integers and floating point numbers - We can use arithmetic op…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn PHP Variables

Start[missing "en.views.course_landing_page.learn-php.course_illustration" translation]