Home arrow PHP arrow Page 3 - Programming PHP: A Beginner`s Guide

Variables - PHP

PHP has been taking the web by storm because of its power and versatility. If you'd like to add PHP-based applications to your web site, keep reading. This series of articles will teach you the language from scratch.

TABLE OF CONTENTS:
  1. Programming PHP: A Beginner`s Guide
  2. PHP Means PHP: Hypertext Preprocessor
  3. Variables
  4. Working with Strings
By: James Payne
Rating: starstarstarstarstar / 19
October 29, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The best way to think of a variable is to think of a box. You store things in them. You can put stuff in them, take things out, move them around, and so forth. If you are an angry UPS guy who has some computer parts we just ordered, you can slam it on the floor and kick it a few times while glaring at all of the employees. Then you can politely ask for the signature and storm out (you know who you are!).

Variables in PHP (and in programming languages in general) store data. Most programming languages are a real pain in the butt and make you define what type of data is being stored. Not PHP. In Soviet Russia, PHP tells you what type of data is in the variable!

(Note: A special thanks to the great world-renowned comedian Yakov Schmirnoff).

Here is how you work with variables:


<html>

<body>


<?php

$the_greatest = "James Payne";

echo $the_greatest;


?>


</body>

</html>

The above code store the string (or text) James Payne in a variable named $the_greatest. We then used echo and told it to print the value of $the_greatest. Which would result in:

  James Payne

A note about naming variables. They must begin with either a letter or an underscore(_) and can only contain letters, numbers, and underscores. Spaces are not allowed. If you wish to use a two or more word name, use either of these methods: $string_name or $StringName. And lastly, a $ must precede the name of the variable, to let PHP know you are using a variable.



 
 
>>> More PHP Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: