Custom Search

Thursday, August 21, 2008

Sort Function

Sort Function:

sort: This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.

rsort: Sort an array in reverse order.

arsort : Sort an array in reverse order and maintain index association. This function sorts an array such that array indices maintain their correlation with the array elements they are associated with.

This is used mainly when sorting associative arrays where the actual element order is significant.

asort : Sort an array and maintain index association...This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.

krsort : Sort an array by key in reverse order..Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.

ksort : Sort an array by key, Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.

uksort : Sort an array by keys using a user-defined comparison function..uksort() will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.

usort : Sort an array by values using a user-defined comparison function..This function will sort an array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.


Tuesday, August 19, 2008

ARRAYS

Arrays: An array can store multiple data using a single variable name, and by using index of the array we can access those variables.

The main advantage of an Array is instead of having many similar variables, you can store the data as elements in an array. Each element in the array can be accessed easily by its ID.

There are three different kind of arrays:

Numeric array - An array with a numeric ID key

Example: $names = array("John","Mark","Harry");

Associative array - An array where each ID key is associated with a value

$name[0] = "John";

$name[1] = "Harry";

Multidimensional array - An array containing one or more arrays. When storing data about specific named values, rather than a numerical array a multidimensional array will do the best.

$num = array("John"=>20; "Harry"=>30);

Array Functions:

array_diff:

If you want to find out difference of two arrays you can use the function array_diff. This function takes two arrays as input and then returns the result array. Syntax of this function is:

$new_array = array_diff ($array1, $array2);

array_count_values

When you need to count the number of time an element is present inside an array you can use array_count_values function. This function returns another array which stores the values the input array and its frequency or the number of occurrence of the value.

The syntax of this function:

$result_array= array_count_values ($input_array)

array_sum

We can store values in an array and calculate the sum of the values inside the array by using the array_sum function.


array_unique

To get a set of unique values from an array we use this function. This will take an array as input and return an array with unique elements. The duplicate elements will not be repeated.

Monday, August 18, 2008

Basics of PHP

A PHP block always starts with < ? and ends with ?> .

Each line in PHP must end with a semicolon. There are two basic statements to output text one is echo and other one is print.

In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.

Variables:

Variables are used for storing values, such as numbers, strings or function results. All variables in PHP start with a $ sign symbol.

A variable name must start with a letter or an underscore "_"
A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($my_variable), or with capitalization ($myVariable)

Examples: $txt = "Hello"; $num = 10;

  

What is PHP?


PHP (Hypertext Preprocessor) is a HTML embeded server side scripting language. (Cross Platform) PHP is a powerful server-side scripting language for creating dynamic and interactive websites.

PHP is the widely-used, free, and efficient alternative to ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code. The PHP syntax is very similar to Perl and C. PHP is often used together with Apache (web server) on various operating systems.

The difference between a static page like HTML and dynamic page like PHP is the way the server interpret the request.

When ever request comes for a static html page the web server returns the page to the client, where as incase of PHP pages the server does not return the page directly to the client. The web server runs the PHP engine and the output of the executed script is posted back to the client machine.

Advantages of PHP:

PHP scripts are executed on the server and it supports many databases (MySQL, Oracle, Sybase etc.).

PHP is an open source software (OSS) and it is free to download and use

PHP files have a file extension of ".php".

PHP combined with MySQL are cross-platform (means that you can develop in Windows and serve on a Unix platform)

PHP runs on different platforms.

PHP is compatible with almost all servers used today.

PHP is FREE to download from www.php.net

PHP is easy to learn.

NOTE: Before you continue with PHP you should have a basic knowledge of HTML and some scripting languages. To learn HTML go to http://benshtml.blogspot.com/


Powered By Blogger