Beginners PHP - Variables
9 posts
Page 1 of 1
hey guys,
I see quite a few PHP tutorials here but not many aiming at the very most basics. I just want to talk a little about variables.
The different types of PHP variables are:
You can manually specify the variable type when you declare it by adding this:
In PHP you can return the variable type like so:
For example I have a style in my HTML Head in my PHP file, instead of using echo ""; on each line do this:
If you want to program with PHP you will need a lamp/wamp server, most popular one for windows is xampp and is free to download: Click here to download Xampp
I recommend Xampp 1.8.2 not 1.8.3 since it's still in Beta and crashes a lot. If you want to use Xampp on your USB or External Harddrive download the .zip version of Xampp and install it to your portable device.
When working with PHP files you will need to start the Apache server, and the MySql server if you want to use databases. The website files go into c:/xampp/htdocs/, this will depend on what drive you install it on though but it's always xampp/htdocs/
To view the files in the browser you will need to navigate to locahost in the browser, also Apache runs on ports 80 and 443 so you will need to be aware of that, if you have an IIS server this usually runs on port 80 too, close IIS or change the conf file of Apache to run on another port, also a lot of programs run on port 443 too, namely vmware. Just close it if you have anything running on that port.
I know this tutorial was for variables but thought I would try and give more information aimed at helping people new the PHP. If you liked my tutorial let me know, if there was anything I was wrong about or need to change anything please let me know
thanks for reading guys
I see quite a few PHP tutorials here but not many aiming at the very most basics. I just want to talk a little about variables.
The different types of PHP variables are:
Boolean
Integer
Float/Double
String
+ a few more but these are the most common
Code: Select all
In PHP when you create your variables you don't need to declare the type because this is done automatically. If you have an integer and change it's value to a string, that data type is automatically changed. <?php
$name = "SmashApps"; //String
$age = 19; //Integer
$birthday = 19.02; //Double
$LikesCoffee = True; //Boolean
?>
You can manually specify the variable type when you declare it by adding this:
Code: Select all
You are the type in brackets before the value. <?php
$name = (String)"SmashApps";
?>
In PHP you can return the variable type like so:
Code: Select all
It would look like this in the browser:<?php
$name = "SmashApps";
echo "The variable \$name has a value of $name and it's type is: "; echo gettype($first);
?>
The variable $name has a value of SmashApps and it's type is: StringIf you are new to PHP and are using it to push a lot of HTML data, try avoid doing that as it can slow down how long it takes to load the page.
For example I have a style in my HTML Head in my PHP file, instead of using echo ""; on each line do this:
Code: Select all
PHP is becoming more popular now since it's trying hard to be more Object-Orientated, also because it's a server side language none of the PHP code will be displayed in the client's browser. <!DOCTYPE html>
<head>
<title>Hello World!</title>
<style type="text/css">
body {
font-family:"Calibri";
}
</style>
</head>
<body>
<?php
echo "Hello world!";
?>
</body>
</html>
If you want to program with PHP you will need a lamp/wamp server, most popular one for windows is xampp and is free to download: Click here to download Xampp
I recommend Xampp 1.8.2 not 1.8.3 since it's still in Beta and crashes a lot. If you want to use Xampp on your USB or External Harddrive download the .zip version of Xampp and install it to your portable device.
When working with PHP files you will need to start the Apache server, and the MySql server if you want to use databases. The website files go into c:/xampp/htdocs/, this will depend on what drive you install it on though but it's always xampp/htdocs/
To view the files in the browser you will need to navigate to locahost in the browser, also Apache runs on ports 80 and 443 so you will need to be aware of that, if you have an IIS server this usually runs on port 80 too, close IIS or change the conf file of Apache to run on another port, also a lot of programs run on port 443 too, namely vmware. Just close it if you have anything running on that port.
I know this tutorial was for variables but thought I would try and give more information aimed at helping people new the PHP. If you liked my tutorial let me know, if there was anything I was wrong about or need to change anything please let me know

Last edited by smashapps on Sun Feb 09, 2014 2:49 am, edited 1 time in total.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
Thanks #benji_19994 and everyone else who gave me a +rep! I love dem reps. lol
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
It would be worth it if you could show examples for integer, boolean etc?
Find my programs on Softpedia
Updated thread
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
Thanks, PHP is good in this thing; we don't need to set the type of Variable! +REP
Find my programs on Softpedia
Thanks #Shim
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
Good tutorial! this is very useful for beginners and apparently for me
i didn't know that you can declare variables with a specific type (String)"SmashApps";

You can find me on Facebook or on Skype mihai_92b
Yeah I learnt it in my PHP class on campus! I will definitely be writing more PHP tutorials, #benji_19994 and I are both writing them together.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023