Tuesday, June 16, 2009

Php basics : error handling, tests, array functs, classes, and scope

Checking if a file exists

if (file_exists($some_file)){
...
}

Basic Error Handling

function($var) or exit("some error");


Printing an array


print_r();


Creating a class

class SomeClass{

private some_var;

public function SomeClass(){}

public function new_fun($r){
print_r($r);
echo $this->some_var;

}

}


Defining an array

$my_array = array('elem1','elem2');

Adding an array element

array_push($array,$elem)


Checking if a key exists

array_key_exists("some_name",$r)


Using a global var in a function

global $global_var;

No comments: