PHP Tips and Tricks
Saturday, November 19, 2011
PHP - Variables
This is a really cool system. Please take a second to read this. Below is a link to a paid to click account. I have tried alot of these schemes but they never lead to anything. This however has the highest paying rates per click, up to 5.5cents per click. Imagine you get 20 ads per day with 5.5cents per ad, then you get $1.1 per day, which is $33 per month, leading to $400 yearly. You tell me, this is a waste of time, but it only takes a couple of minutes a day, and you can withdraw the money anytime you desire. And it has referral bonuses aswell. I would try it out, after all it's for free. I am really glad I found this system. True, it didn't change my life because the amount you get doesn't compare to a day job, however, getting $400 at the end of the year just by clicking on ads is quite self satisfactory. Try this out and you will not be disappointed. Please note that you can cancel your account anytime you desire and no emails will pester you after you cancel your account. CLick on the banner below, and it will take you to the registration page:
Hi and welcome to my PHP tips and tricks blogging site.
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
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
Subscribe to:
Posts (Atom)