In my blogs, i will guide beginners into understanding the simplicity of using PHP as a programming language and will provide examples to prove any theory mentioned.
First of all, a brief introductory summary to explain what PHP is exactly.
PHP stands for PHP: Hypertext Preprocessor. It is a server-side scripting language. Server-side scripting is a web technology that allows custom HTML to be delivered to a client machine where the generated code is processed on the web server before it is sent the the users computer. Each class or PHP file starts with the same php tag:
<?php
Each statement in PHP ends with a semi-colon, i.e. ;.
Variables in PHP all start with the dollar sign, $. It does not even need to be declared prior to a value being given to it. In simple terms, one can just assign 10 to a variable name test as
$test = 10;
Variables in PHP do not contain data types. Also, the data type of a variable can change while it is still existent in a class or a function. E.g. lets remember the value of 10 assigned to the variable $test. Now i want to assign "testing 123" to the same variable. Therefore, i just equate the string to the variable name:
$test = "testing 123";
In the first example, I will create 2 variables, named x and y, and i will add both variables to create a final variable, named total.
$x = 5;
$y = 4;
$total = ($x + $y);
Please note that conditional operators in PHP follow the BODMAS rule (Brackets Of Division Multiplication Addition Subtraction)
To save the current date in a variable, you need to call the date() function. It is important that if you desire to format your date, you specify the format in the brackets of the date() function:
$today = date('Y-m-d');
To display a variable on the webpage, all you need to do is call the echo method followed by your variable and ;
echo $today;
This will display 2011-11-19 on the web page.
Variables can also be concatenated in PHP. Consider you have 2 variables, one containing the name of a person, and the other containing his/her surname. A full stop will concatenate both your variables:
echo $name . ' ' . $surname;
The above example will display name (space) and surname. E.g. Joe Smith.
Arrays are a powerful tool in PHP. To create an array just assign the variable as an array(), $arr_list = array();. To add to this array, simply use the variable name followed by square brackets and equate to your value. Please note that if you do not specify anything in the brackets, PHP assumes that you want to increment the key to the next number.
$arr_list[] = "this is list 1";
$arr_list['a'] = "this is list a";
To display the values of an array for testing purposes, call the var_dump() method. If you put any string or variable in the brackets, PHP will display your required text onto the page. Therefore, if var_dump($arr_list); is called, the below will be displayed:
array{ [0] = "this is list 1"
[a] = "this is list a"
}
This was the first tutorial which explained variables in PHP in a very easy way. Practice with variables until you get the hang of how they work and follow my future blogs on PHP where I shall explain how to add a database to your code, upload files, create log files, anything related to PHP.
If you have any questions, please comment in the below section and I will be happy to answer any of your questions. And please do remember that this blog is for beginners only.
Thank you and have a nice weekend.
Luke
DreamHost coupon code List Your Website
This php tips are really very helpful to me, please update your blog regularly.
ReplyDeleteRegards,
web designing course in chennai|web designing training
Very helpful tips, please give more suggestion in your upcoming blog.
ReplyDeleteRegards,
DOT NET Training in Chennai
Wonderful post..Thank you for updating such a informative content..
ReplyDeleteRegards,
PHP Training in Chennai | PHP Course in Chennai | PHP Training Institute in Chennai
Informative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.
ReplyDeleteclick here designs
click here download com.diconline.rakroid now
click here digital glassdoor
click here digital ltd
click here digital google review
Given so much information in it. its very useful .perfect explanation about Dot net .Thanks for your valuable information.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery