Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ** PHP - Hypertext Preprocessor
- ** Server side scripting language
- ** Released Date : 1994
- ** Created By: Rasmus Lerdorf
- ** Most CMS used PHP -
- * WordPress
- * Joomla
- * Drupal
- ** Most popular website used PHP -
- * Facebook
- * Yahoo
- * Wikipedia
- * Flicker
- */
- ?>
- <?php
- //variable
- $myfriend = 'my friend name is jahed hossain';
- $br = '<br>';
- echo $myfriend . $br;
- /*
- Data types
- ====================
- 1. String - '', " " ;
- 2. Integer - 1,2,3....
- 3. Float - 1.1,1.2,1.3....
- 4. Bollean - true/false
- 5. Null -
- */
- $name = 'Humayun ahmed'; //string
- $age = 21; //integer
- $result = 5.0; //float
- echo $name . $br . $age . $br . $result . $br; //concatenation
- /*
- Operator
- =======================
- 1. Arithmetic Operator
- 2. Assignment Operator
- 3. Logical Operator
- 4. Comparison Operator
- 5. Array Operator
- 6. Increment/decrement Operator
- 7. String Operator
- */
- /*
- 1. Arithmetic Operator
- =======================
- 1.1 - Plus : +
- 1.2 - Mynus : -
- 1.3 - Into : *
- 1.4 - Devided : /
- 1.5 - Modulas : %
- */
- $father = 60;
- $son = 25;
- $plus = $father + $son; //Plus
- $mynus = $father - $son; //Mynus
- $into = $father * $son; //Into
- $devided = $father / $son; //Devided
- $modulas = $father % $son; //Modulas
- echo $plus . $br;
- echo $mynus . $br;
- echo $into . $br;
- echo $devided . $br;
- echo $modulas . $br;
- /*
- 2. Assignment Operator
- =======================
- 2.1 - Plus-equal : +=
- 2.2 - Mynus-equal : -=
- 2.3 - Into-equal : *=
- 2.4 - Devided-equal : /=
- 2.5 - Modulas-equal : %=
- */
- $age = 20;
- $age = $age += 5; //Plus-equal
- //$age = $age -= 5; //Mynus-equal
- //$age = $age *= 5; //Into-equal
- //$age = $age /= 5; //Devided-equal
- //$age = $age %= 5; //Modulas-equal
- echo $age . $br;
- /*
- 3. Logical Operator
- =======================
- 3.1 - (or) - ||
- 3.2 - (and) - &&
- 3.3 - (not) - !
- */
- $username = 'humayunahmed8';
- $password = 'ha154248';
- // (and)
- if($username == 'humayunahmed8' && $password == 'ha154248'){
- echo 'login success' . $br;
- }else{
- echo 'login failed' . $br;
- }
- //(or)
- /*
- if($username == 'humayunahmed8d' || $password == 'ha154248'){
- echo 'login success';
- }else{
- echo 'login failed';
- }
- */
- /*
- 4. Comparison Operator
- =======================
- 4.1 - (equal) - ==
- 4.2 - (not equal) - !=
- 4.3 - (not equal) - <>
- 4.4 - (greater than) - >
- 4.5 - (greater than or equal to) - >=
- 4.6 - (less than) - <
- 4.7 - (less than or equal to) - <=
- */
- $humayun = 20;
- $jahed = 18;
- if($humayun > $jahed){
- echo 'true' . $br;
- }else{
- echo 'false' . $br;
- }
- $humayra = 17;
- if($humayra >= 18){
- echo 'Ready for marriage' . $br;
- }else{
- echo 'not ready for marriage' . $br;
- }
- /*
- 5. Array Operator
- =======================
- 5.1 - Indexed Array
- 5.2 - Associative Array
- 5.3 - Multidimensional Array
- */
- // 5.1 - Indexed Array
- $father = array(1=>'humayun','foysal','fariya');
- //print_r($father);
- echo $father[1] . $br;
- // 5.2 - Associative Array
- $mother = array('humayun'=>21,'foysal'=>18,'fariya'=>10);
- //print_r($mother);
- echo $mother['foysal'] . $br;
- // 5.3 - Multidimensional Array
- $humayun = array(
- 'humayra' => array(
- 'class' => 12,
- 'group' => 'Business Studies',
- 'hobby' => 'Reading',
- ),
- 'abrar' => array(
- 'class' => 10,
- 'group' => 'Science',
- 'hobby' => 'Sleeping',
- ) ,
- 'jahanara' => array(
- 'class' => 9,
- 'group' => 'Humanities',
- 'hobby' => 'Singing',
- )
- );
- //print_r($humayun);
- //echo $humayun['humayra']['hobby'];
- //echo $humayun['abrar']['group'];
- //echo $humayun['jahanara']['class'];
- echo $humayun['humayra']['hobby'].$br.$humayun['abrar']['group'].$br.$humayun['jahanara']['class'] . $br;
- /*
- Loop
- ==========
- 1. for loop
- 2. while loop
- 3. foreach loop
- */
- //1. for loop
- //for(initialization,condition,increment/decrement);
- for($i=100;$i>=1;$i--){
- echo $i . $br;
- }
- //1++
- for($b=1;$b<=100;$b++){
- echo $b . $br;
- }
- //2+2=4+2=6+2=8
- for($b=2;$b<=100;$b+=2){ // assign
- echo $b . $br;
- }
- //1+2=3+2=5+2=7
- for($b=1;$b<=100;$b+=2){ // assign
- echo $b . $br;
- }
- //2. while loop
- $n=1;
- while($n<=100){
- echo $n . $br;
- $n++;
- }
- //3. foreach loop
- $rahman = array('ramim'=>20,'nadim'=>25,'hridoy'=>30,'sakib'=>28);
- foreach($rahman as $child=>$year){
- //echo $child . $year . $br ;
- echo $child . ' age is' . $year . $br;
- }
- ?>
Add Comment
Please, Sign In to add comment