WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Accespted Variables in PHP Wed Dec 29, 2010 12:42 am

Unknown Data

Unknown Data
Registered Member
Registered Member
Variables in PHP
Learn PHP - part 3


To define a variable
In PHP are we indicating our variables with a dollar sign followed by a name, but remember also that PHP is case-sensitive, ie. there is a differences between big and small letters.
All variables starts with big letters or a underscore (no numbers are allowed) followed by the name written with letters or numbers.

Here is some examples of the variables:

Code:
<?php
$var = "Now am I";
$vaR = "writting something";
$Var = "by using";
$vAr = "the PHP variables.";
echo "$var $vaR $Var $vAr";
?>

In a document will it look like this:

Now am I writing something by using the PHP variables.

Variables as reference
If we want to make a reference with another variable, are we only going to add this sign "&", before the variable.

I've added a example again:

Code:
<?php
$var1 = "Hello World!"; // var1 contains "Hello World!"
$var2 = &$var1; // var2 contains reference to var1
echo "$var1 $var2";
?>

It will then look liek this:

Hello World! Hello World!

Variables in a form
Try pasting this inside your document and you'll see that it'll show up a funny little thing.

I'll start explaining it after you've viewed the whole source
Code:
<html>
<head>
<title>Example</title>
</head>
<body>

<form method="post" action="<? echo $PHP_SELF; ?>">
Enter your name: <input type="text" name="name">
<input type="submit" value="Start">
</form>

You entered following name:
<?php
echo $_REQUEST['name'];
?>

</body>
</html>

All right. There isn't the big to explain about the HTML form. The only special stuff that we want to know more about is the PHP_SELF. This part of the code will return the file, plus the content inside the variables name.
The echo $_REQUEST part will return the content inside the form field "name". In stead of using the $_REQUEST, could I've also used $_POST, because that's the method for sending data in my case. If I want to receive something, can I use $_GET.

A little bit about array
Before we switch to the next tutorials are we taking a short look at arrays.

In the example have I defined an array as $fruits, that contain five fruits. Each of these names can I flow the command echo $fruits[]. Remember that the first name should have [0]! '

Code:
<?php
$fruits = array(apple, pear, banana, orange, grape);
?>

To find the fruit banana am I writing echo followed by $fruits[2];, if I then want to find grape am I writing $fruits[4]; instead of $fruits[2]; etc.

In the next lesson will we take a look at loops.

Notice : This tutorial is copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators.

http://woops.dk

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum