Home arrow PHP arrow Page 3 - PHP 101 (Part 1) - Secret Agent Man

A Case Of Identity - PHP

PHP is the hottest scripting language around - and with the release of PHP4, more and more developers are looking at it as a rapid Web development tool. This new series of tutorials is aimed at getting novice programmers up to speed on the language, and the first article covers variables, operators and the include() function call. Exploding chewing-gum is optional.

TABLE OF CONTENTS:
  1. PHP 101 (Part 1) - Secret Agent Man
  2. Bond...James Bond
  3. A Case Of Identity
  4. The Toy Shop
  5. Weapons To Die For
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 36
July 31, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Variables are the bread and butter of every programming language...and PHP has them too. A variable can be thought of as a programming construct used to store both numeric and non-numeric data; this data can then be used in different places in your PHP scripts.

PHP supports a number of different variable types: integers, floating point numbers, strings and arrays. In many languages, it's essential to specify the variable type before using it; for example, a variable may need to be specified as type "integer" or type "array". Give PHP credit for a little intelligence, though - the language can automagically determine variable type by the context in which it is being used.

Every variable has a name - in PHP, a variable name is preceded by a dollar [$] sign and must begin with a letter, optionally followed by more letters and numbers. For example,

$popeye $one $INCOME are all valid PHP variables.

Note that variable names in PHP are case sensitive - so

$me

is different from

$Me

or

$ME

Here's a simple example which demonstrates PHP's variables:


<html> <head> <title>Bonding With PHP</title> </head> <body> So who do you think you are, anyhow? <br> <? // set up some variables $fname = "James"; $lname = "Bond"; ?> <b><? echo "The name's $lname...$fname $lname!"; ?></b> </body> </html>
In this case, the variables $fname and $lname are first defined with string values, and then substituted in the echo() function call. Just as an aside...the echo() function is another important PHP function, and one that you'll be using a great deal over the next few lessons. It is commonly used to display output.

Synonymous to echo() is print(), which does exactly the same thing - take a look at the example below, which demonstrates how to use it.


<html> <head> <title>Bonding With PHP</title> </head> <body> So who do you think you are, anyhow? <br> <? // set up some variables $fname = "James"; $lname = "Bond"; ?> <? print("<b>The name's $lname...$fname $lname! </b>"); ?> </body> </html>
Note how we've included the HTML <b> tag within the string to be displayed in this example...you can do this too. Really.

 
 
>>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

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: