You are on page 1of 4

REQUIREMENTS

================
(1)Web Server(apache)
(2)PHP (at-least version 5.6)
(3)Database->My SQL
(4)Best Text Editors(Notepad,Visual Stdio,Brackets)
(5)Any Web Browser
OUTPUT
=========
(1)echo "Hello Anuj";
(2)Syntax->
VARIABLES
===========
RULES FOR VARIABLES
====================
(1)Start with $ $name
(2)Contain dashes(-) $my-Name
(3)underscore(_) $my_name
(4)letters(a,b,.... A,B,....) $myName
(5)numbers(1,2,.........) $name12
(6)Case Sensitive e.g a is not equal to A $name is not same to $Name
(7)No space $nam e
(8)Cant start with numbers $12name
(9)Bad Pratice $-name, $_name
EX- $name = "Anuj"
echo $name;
CONSTANTS
============
(1)Once we declare the variable then we can not change the value.
by using define();
EX->simple variable->$name
constant variable->define("value_of_pi", 3.14);
echo : "Value of Pi" . value_of_pi;
*We can not redeclared the variable with same name.
STRINGS FUNCTION
======================
(1)ucfirst()
(2)ucword()
(3)strtolower()
(4)strtoupper()
(5)str_repeat($compine, 4)
(6)substr($combine,5 ,10)
(7)strpos($combine, come)
(8)strchr($combine, "R")
(9)strlen()
(10)strstr($combine, "come")
(11)str_replace("sit","stand",$combine)
(12)trim()->it removes the white space.
NUMBERS
==========
COVERED IN PRACTICAL
ARRAYS
========
(1)Array is a collection of data.
(2)Syntax -> array()
(3)By using print_r(); we can show array type.
ARRAYS FUNCTIONS
=====================
(1)implode()->It returns a string from the elements of an array.
(2)explode()->explode() function breaks a string into an array.
(3)current()->next()====But i dont know
IF-STATEMENTS
================
(1)EX-if(condition){
--------
}elseif(condition){
-----------
}else{
---------
}
OPERATORS
=============
(1)Operator Precedence->() , * , / , +, -
(2)Logical Operator->(1)And operator->&&->both condition should be true
(2)Or operator->|| At least one condition should be true.
(3)Ternary Operator->Syntax->Condition? true : false;
FOREACH LOOP
================
(1)foreach loop->foreach loop works only on arrays, and is used to loop through each
key/value pair in an array.
Syntax->foreach ($array as $value) {
code to be executed;
}
STATIC VARIALBES
===================
There are 3 types of variables scope:
(1)global variable
(2)locale variable
(3)static variable
(1)global variable->A variable declared outside the function has a global scope and can
only be accessed outside a function.
EX-
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "
Variable x inside function is: $x

";
}
myTest();
echo "

Variable x outside function is: $x

";
?>
***PHP The global Keyword->The global keyword is used to access a global variable
from within a function.
EX-
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y; // outputs 15
?>
***PHP also stores all global variables in an array called $GLOBALS[index]. The index
holds the name of the variable. This array is also accessible from within functions and
can be used to update global variables directly.
EX-
$x = 5;
$y = 10;
function myTest() {
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
}
myTest();
echo $y; // outputs 15
?>
(2)static variable->Normally, when a function is completed/executed, all of its variables
are deleted. However, sometimes we want a local variable NOT to be deleted. We need
it for a further job.
EX->function myTest() {
static $x = 0;
echo $x;
$x++;
}

myTest();
myTest();
myTest();
**if you are not using static keyword the variable value is always will be 0.
(3)Locale variable->A variable declared within a function has a LOCAL SCOPE and can
only be accessed within that function:
Ex->
function myTest() {
$x = 5; // local scope
echo "

Variable x inside function is: $x

";
}
myTest();
// using x outside the function will generate an error
echo "

Variable x outside function is: $x

";
?>

You might also like