| Recent Articles |
Google To Charge For AdWords API The current free quota system used in capping developer usage will be replaced by a usage-based fee system that will charge developers 25 cents per 1,000 quota units used.
Nexaweb Builds Ajax Client For Developers Privately held Nexaweb Technologies recently announced the addition of an Ajax client to its Rich Internet Applications (RIAs) development platform.
DCamp Socialtext is opening it's doors to host DCamp, the first ad-hoc event focused on design & user experience, May 12th & 13th.
IBM Polishes SOA Blitz With AJAX Over the next few months, IBM is launching a massive set of products and services to bolster implementation of service-oriented architecture in businesses that use WebSphere software. Of particular interest to many is the deployment of the new WebSphere Portal using AJAX.
Google Maps The Way To Version 2 The official launch of the Google Maps API Version 2 provides a number of tweaks to enhance its performance and decrease the number of memory leaks that happened in previous versions.
Why Comply? The Movement to W3C Compliance The Internet: a powerful tool with endless possibilities to advance business, connect people and share information.
Importance
of W3 Standards
When the Internet first began its boom, the technologies
used in design were forgiving. W3-Compliance wasn't
as necessary because there were fewer browsers,
fewer users, and overall fewer technologies in use.
CSS Cursors - How To Use Them
One thing that CSS allows us to use for screen presentation
are alternate cursors. This is not the idea of downloading
or forcing a download of a cursor, as was done in
the past (though that is possible as well), but...
|
|
04.20.06
Variables In PHP
By Shedboy
This is part 1 in a series of articles.
Variables
A variable is an area of memory which is set aside to store information. This is assigned an identifier by the programmer . You can recognise variables in PHP because they are prefixed with the dollar ( $ ) sign . To assign a variable you use the assignment operator ( = ) . Here is an example of this.
$name = "shedboy";
$intDaysInWeek = 7;
In the first example the variable identifier is $name and the string value "iain hendry" has been assigned to it . In the second example the variable identifier is $intDaysInWeek and the number 7 is assigned to it . Note that in the number example we do not surround the variable with quotes in this way. PHP treats this as a numeric value but if we had put quotes around it then PHP would have treated it as a string.
Variable Naming
There are some guidelines to follow for naming variables in PHP and these are as follows .
1. All variable names must begin with a letter or underscore character .
2 . The name of the variable can be made up of numbers , letters , underscores but you can't use charcters like + , - , & , £ , * , etc.
One important thing to note if you are coming from another programming language i that there is no size limit for variables .
Case Sensitivity
One thing that causes many hours of hair pulling and anguish is case sensitivity , PHP is case sensitive (some languages are not) . Here is an example of what I mean.
<<?php
$myname = "shedboy";
echo $Myname";
?>>
Now we all know what we want to do: declare a variable , assign it the value of "shedboy" and then print this on the screen but in this example we have mis-spelled the variable name. When run, the following error is displayed on the screen.
Warning: Undefined variable: Myname in D:\testsample.php on line 3
Example
Using your favourite HTML editor enter the following:
?php
$url = "http://www.programmershelp.co.uk";
$rank = 1;
echo "Our favourite site is ".$url;
echo "
";
echo "It is numbered ".$rank;
?
Here is the output you should get:
Our favourite site is http://www.programmershelp.co.uk
It is number 1
About the Author: Owner and founder of Programmers help and maxidirectory to name just a few of the many sites.
|