Php
variables:-
Starting
with $sign
When u
assing text to any variable then use double quotes for values “myname”
When u
assing number then no need $age=22;
Remember
always end variables with semicolon;
Php
functions:-
Function
function name()
{
// kuch bhi
echo ho sakta hai using variable,if else,etc
//hamein
both variable and echo inkey andar ki karna hai ……agar bahar karna hai to
argument use karney padtey hai okk see later
}
Dekho ab in
do curly brackets ke andar job hi echo ya print karwaogey use aap access kar
saktey ho outside funcyion using
Function
name();
Now
arguments or pass value to functions :-
Function
functionname($a) //semicolon ni lagega
and use $ bcz hamein var assign karna hai
{
// ab chahey
aap yaha par echo karwado aur values variable
ki outside curly assign kardo to bhi chalega
}
//here u can
assign value like $a=30; and get output functionname($a);
//remember
to use argument in output of function okk
Now you can
also get ur output in another variable like this :-
Function
abc($a)
{
Print $a;
}
$a=”thisis
a”;
$c=abc($a); //function output ek alag variable mein hai
aur kuch nahi hai
Print $c;
?>
Note
header function:-
Header(“location:http://www.google.com”);
?>
Include
function:-
Include(“textfile.txt”);
?>
Strlen
function:-
Use to
return length of string
Echo strlen
“hello world!”;
?>
//it will
give output 12 sochney ki baat hai without using any variables
Concatenation
operator: dot . used to join two strings
kkey
Strops
function :-
Used to search
character/string with in a string
Echo strpos(
“hello world”,”world”);
?>
Output will
be 6 not 7 bcz string count from 0 not 1
Now
if else
$a=34;
If
(condition) { } Else { }
?>
Switch
statement
Switch($variable
name) //semicolon yahan par ni lagega
{
case ‘what u want to check’;
//code
Break;
Case
‘another’;
//code
…….
Example live
$x=1;
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>
Iski output
ayegi number 1 but agar $x ki value 3 kardey to number 3 ayegi bcz ………bcz swith
case ko match karega okkey
Agar
$x=”tect hota like car ” to hamein kuch istarah case likhna panda tha in quotes
Case ‘car’;
Echo”this is
car”;
Break;
Case’aeroplane’
………………..
………………..
No comments:
Post a Comment