You are on page 1of 4

Php.

ini file for changing php configuring, you need to restart the server if you made a
change

<?php phpinfo(); ?>

Turn on php with <?php

End with ?>

Short open tags (considered bad form) :: <? ?> and <?= ?>

Stander form <?php ?>

Comment using // or # or /* */ (java + python comment)

Variable Name:

1. Start with a $

2. Followed by letter or underscore

3. Can contain letters, numbers, underscores, or dashes

4. No space

5. Case-sensitive

Ex: $item, $Item, $this-variable(bad STYLE), $this_variable, $_book , $___book

String can contain html

 Echo “Hello world <br \>”;

“..” inside also can contain variable

Doesn’t not work with single quote ‘…..’

 “$variable again”;  x again;

 Better style “{$variable} again”;

<?php

$variable_Here

?>
<?php

$variable_Here // this does refer to the same object

?>

. (Pe riod) is use as + in java to combine string

Array_Functions:

Count($array) // count how many items in an array

Max($array) // find the max value in the array

Min($array) // find the min value in the array

Sort($array) // sorting the array

Rsort($array) // reverse sorting the array

Implode(“ * “, $array) // creating from an array to a string, items separate by *

Explode(“ * “, $string) //creating from a string to an array, separating by *

In_array(element, $array) // find how many elements in the array, return T/F

Boolean:

True representing by value 1

False representing by null, empty

Variable Function

Check if $var is set, return boolean

Isset($var)

Unset $var

Unset($var)
Check if $var empty or value 0 or string “0”

Empty($var)

Gettype($var1) // getting the type of $var1

Settype($var2, typeCasting) // setting $var2 to typecasting(string)

// settype($var2, “string”)

(int) $var1 does work too

Is_array($var1);

…bool(…)

…float(…)

…int(…)

…null(…)

…numeric(…)

…string(…)

How to define a Constant:

Define(“MAX_WIDTH”, 980);

Looping

for each loop: (only work for array)

foreach($array as $value) :: loop through all array elements

statement;

foreach($array as $key => $value :: if key didn't defined, it


would use its index position

statement;
:: continue ::

if($val = 5){

continue } :: in an loop, it will skip anything, continue without doing


anything.

Continue <==> break

POINTER:::::::::::::::::::::)

current($array) – return the current array pointer is;)

next($array)

reset($array)

FUNCTION::::::

function func_Name ($arg){

statement;

global $var

FUNCTION DEFAULT VALUE:

function pain($color = “red”){

statement; } :: if no arg is passing when calling the function,


$color= red; else $color = arg;

You might also like