array_multisort()

This function Sort multiple or multi-dimensional arrays.
It can be used to sort several arrays at once, or a multi-dimensional array by one or more dimensions.
Associative (string) keys will be maintained, but numeric keys will be re-indexed.

Syntax: array_multisort(array1,sort order,sort type,array2,array3…)

Description:

array_multisort(array1,sorting order,sorting type,array2,array3…)

The first argument “array1” is Required. It specifies an array.

The second argument “sort order” is Optional. It specifies the sorting order. Possible values:

* SORT_ASC Default. Sort in ascending order (A-Z)
* SORT_DESC sort in descending order (Z-A)

The third argument “sort type” is Optional. It specifies the type to use, when comparing elements.
Possible values:

* SORT_REGULAR Default. Compare elements normally
* SORT_NUMERIC Compare elements as numeric values
* SORT_STRING Compare elements as string values

The fourth argument “array2” is Optional.It specifies an array.
The fifth argument “array3” is Optional.It specifies an array.

Example:
Code:

$a = array("10", 45, 23, "d");
$b = array(1, 3, "2", 3);
array_multisort($a, $b);

print_r($a);
print_r($b);

Output:

Array ( [0] => 10 [1] => d [2] => 23 [3] => 45 )
Array ( [0] => 1 [1] => 3 [2] => 2 [3] => 3 )

strnatcasecmp()

This function compares two strings using a “natural” algorithm.

In a natural algorithm, the number 5 is less than the number 15. In computer sorting, 15 is less than 5, because the first number in “15” is less than 5.

This function returns:

* 0 – if the two strings are equal
* <0 - if string1 is less than string2 * >0 – if string1 is greater than string2

Syntax: strnatcasecmp(string1,string2)

Description:

The first argument “string1” is Required. It specifies the first string to compare.
The second argument “string2” is Required. It specifies the second string to compare.

Note: This comparison is case insensitive.

Example:
Code:

echo  strnatcasecmp("5Hello!","15Hello!");
echo "
"; echo strnatcasecmp("15Hello","5Hello");

Output:
-1
1

strnatcmp()

This function compares two strings using a “natural” algorithm.

In a natural algorithm, the number 5 is less than the number 15. In computer sorting, 15 is less than 5, because the first number in “15” is less than 5.

This function returns:

* 0 – if the two strings are equal
* <0 - if string1 is less than string2 * >0 – if string1 is greater than string2

Syntax: strnatcmp(string1,string2)

Description:

The first argument “string1” is Required. It specifies the first string to compare.
The second argument “string2” is Required. It specifies the second string to compare.

Note: This comparison is case sensitive.

Example:
Code:

echo strnatcmp("5Hello!","15Hello!");
echo "
"; echo strnatcmp("15Hello","5Hello");

Output:
-1
1

soundex()

This function Calculate the soundex key of a string.

Syntax: soundex ( string )

Description:

The argument “string” is Required. It specifies to string check.

This soundex function returns a string 4 characters long, starting with a letter.

Example:
Code:

$str = "Altar";
echo soundex($str);

Output:

A436

metaphone()

This function calculates the metaphone key of a string.

A metaphone key represents how a string sounds if said by an English speaking person.

This function can be used for spelling applications.

This function returns the metaphone key of the string on success, or FALSE on failure.

Syntax: metaphone(string,length)

Description:

The first argument “string” is Required. It specifies the string to check.
The second argument”length” is Optional. It Specifies the maximum length of the metaphone key

Example:
Code:

$str1 = "alter";
$str2 = "altar";

echo metaphone($str1);
echo "
"; echo metaphone($str2);

Output:

ALTR
ALTR

Page 1 of 1212345...10...Last »
eXTReMe Tracker