Skip to main content
Menu
CodeBabes
  • Create new account
  • Request new password

or

  • Sign in with Twitter
  • Code
  • Babes
  • Sign Up
  • Log In

Pass the QUIZ to the PHP Variables video

PHP Virgin Quiz

Study More
PHP Virgin

To run PHP code it needs to be processed by a web server, it can be a local sever you run on your computer, but you need something to process the PHP.

What is the correct opening tag for PHP?

In simple terms what does a function do in programming?

If you inspect the source of a web page, will you ever see the PHP code?

In the following code snippet, 'print' is what?

<?php
print("Hello beautiful world!");
?>

Zuckerberg wrote Facebook with PHP. What a bad ass.

Share the Love

  • Tweet

PHP Variables

So, do you remember x and y from algebra? I’m sure you’ve used the Quadratic formula like a million times since high school! Or how about the pythagorean theorem? A squared plus b squared equals C squared? All those x’s and y’s and a’s and b’s are variables that represent a value.

PHP also lets you create variables to hold information. These variables can be numbers, like in algebra. There are two different types of numbers in PHP, integers and floats. Integers are regular numbers, 1, 2, 3, 4, -10. Floats are decimal numbers, like 2.7, or 0.345. In PHP, you can usually ignore the differences between the two. Variables can be words or letters like “Hello world”. This is known as a string. They can also be more complex things like arrays, objects, or files, but we’ll get to those later.

Variables are declared with a dollar sign, followed by the name of the variable. How pimp is that? Cash money ya’ll.

Remember that variables in PHP are case sensitive. That means that $name and $NAME are not equivalent. As a general rule, try to make your variable names make sense. Basically, don’t name them random shit. Or the next person who looks at the code is going to think you’re on crack. And if you have to look back at your code in a few months you’ll probably think the same thing.

Variables can contain letters, numbers and underscores, but must start with a letter or underscore.

Let’s create a variable called, my name and assign it a value, umm like my name:

$my_name = ‘desiree’;

We can now print this value to the screen like,

print($my_name);

There are lots of things we can do with variables. We can do math, for example:

$x = 10;
$y = 1 + $x;

print($y); // Shows 11

The basic math operators are addition, subtraction, multiplication, division. Pretty much what you’d expect.

You can also combine strings together, called concatenation. It looks like:

$say_my_name = ‘Hello ’ . $my_name;

There’s a second way we can combine strings together:

$say_my_name = “Hello $my_name”;

If we use double quotes on our string, PHP automatically substitute the values of any variables in the string. Pretty handy.

Next up we’ll talk about conditional statements and you better be paying attention!

Questions or Comments?

Lessons

  • PHP Variables
  • PHP Conditionals
  • PHP Arrays
  • PHP Loops
  • PHP Functions
PHP Virgin

Downloads

SignUp & Subscribe

What the What?

Lessons: 41

Much more to come!

50/50 Entertainment and Education. Learning doesn't have to be boring :)

Our Philosophy

Contact

  • support
  • Tweets!
  • Youtube
  • Google Plus
  • Facebook

Stuff

  • Blog
  • Sign Up
  • All Babes
  • All Courses
  • Become a CodeBabe!
  • MAKE A LESSON WITH CODEBABES!

Recent Courses

Internet Virgin
SEO Virgin
HTML Virgin
CSS Virgin
Programming Virgin with Javascript

Learn to Code with Babes

Copyright © 2025 CodeBabes.com • Made with

  • Privacy Policy
  • Terms of Use
Close Menu
  • Blog

  • All Courses
  • Android Virgin
    • Android Studio Tour
    • App Layout in Android Studio
    • Java Variables, Java Data Types & Android Views
    • Java Event Handling in Android
    • Android Intents, OOP This, Variable Scope
    • Passing the Data with Android Intents & Finish
    • Complete the Android App with Launcher Icons & APK
    • Android Happy Ending
  • Internet Intro
    • Backend Development
    • Front End Web Development
    • Programming Tools you Need
    • Hosting and Domain Names
  • HTML Virgin
    • HTML Text Tags
    • HTML Links and Images
    • HTML Layout with HTML 5
    • HTML Tables
  • CSS Virgin
    • Where to Stick your CSS
    • CSS Properties, Sizes and Colors
    • CSS Selectors
    • CSS Box Model
  • Programming Virgin
    • Variables in Programming
    • Programming Intro Conditional Statements
    • Programming Intro to Arrays
    • Programming with Loops
    • Programming with Functions
  • PHP Virgin
    • PHP Variables
    • PHP Conditionals
    • PHP Arrays
    • PHP Loops
    • PHP Functions
  • SEO Virgin
    • Make Google Love You
    • Understanding Keyword SEO
    • Optimizing for SEO
    • Technical SEO