Skip to content

Latest commit

 

History

History
124 lines (106 loc) · 2.4 KB

index.org

File metadata and controls

124 lines (106 loc) · 2.4 KB

PHP

Introduction

  • Language for developing Dynamic web applications
  • PHP scripts run on the server
  • A PHP program may contain HTML,CSS and JS along with it
  • “.php” is the file name extension

Variables

	$name = "Rick";
	$money = 10.5;
	$boolean = true;
	$age = 30;

A letter must start with underscore or a letter.
Variables names are case sensitive.

	echo "My name is ". $name . "My age is $age";
	echo " I have $money in my pocket."; 

Variable Scope

  • Global Variables
  • Local Variables
  • Static Varibles

Data Types

  • String
  • Integer
  • Float
  • Integer
  • Boolean
  • Array
  • Object

Arrays

  	$colleges = array("NIST","Kathmandu University","St.Xaviers");
  	var_dump($colleges);
  	echo $colleges[0];
  	echo $colleges[1];

Associative Arrays:

  	$bio = array("jack" => "12","crow" => "14","zen" => "18");
  	foreach($bio as $name => $age) {
  			echo $name . "=" . $age;
  			echo "<br>";
  	}

Conditions

  	if (condition) {
  			// code to be executed 
  	} elseif {
 		// code to be executed 
  	} else {
 		// code to be executed 
  	}

Loops

While loop

   	$x = 0;
   	while ( $x <= 25) {
   			echo "The number is: $x";
   			$x++;
   	}

For loop

	for (i = 0; i < 10; i++) {
			echo "number: $i";
	}

Functions

	function function_name(parameters) {
			// code to be executed;
	}
		function_name(parameters);

Form Processing