Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-03-2009
Member
 
Join Date: May 2008
Posts: 37
Array Functions in PHP

Array Functions in PHP

array() - Creates an array
array_change_key_case - Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
PHP Code:
array array_change_key_case  ( array $input  [, int $caseCASE_LOWER  ] ) 
array_chunk() - Splits an array into chunks of arrays.
array_combine() - Creates an array by using one array for keys and another for its values.
array_count_values() - Returns an array using the values of the input array as keys and their frequency in input as values.

Eg.

PHP Code:
<?php
$array 
= array(1"hello"1"world""hello");
print_r(array_count_values($array));
?>
Output :

Quote:
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
array_diff() : Compares array values, and returns the differences

array_diff_assoc() : Compares array keys and values, and returns the differences.
Reply With Quote
  #2  
Old 26-03-2009
Member
 
Join Date: May 2008
Posts: 37
Re: Array Functions in PHP

array_filter : Iterates over each value in the input array passing them to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.

Examples

PHP Code:
<?php
function odd($var)
{
    return(
$var 1);
}

function 
even($var)
{
    return(!(
$var 1));
}

$array1 = array("a"=>1"b"=>2"c"=>3"d"=>4"e"=>5);
$array2 = array(6789101112);

echo 
"Odd :\n";
print_r(array_filter($array1"odd"));
echo 
"Even:\n";
print_r(array_filter($array2"even"));
?>
Output

Quote:
Odd :
Array
(
[a] => 1
[c] => 3
[e] => 5
)
Even:
Array
(
[0] => 6
[2] => 8
[4] => 10
[6] => 12
)

array_diff_ukey() : Compares array keys, with an additional user-made function check, and returns the differences.

array_merge() : Merges one or more arrays into one array.

array_merge_recursive() : Merges one or more arrays into one array

array_multisort() : Sorts multiple or multi-dimensional arrays

array_pad() : Inserts a specified number of items, with a specified value, to an array.

array_pop() : Deletes the last element of an array.

array_product() : Calculates the product of the values in an array
Reply With Quote
  #3  
Old 26-03-2009
Member
 
Join Date: Jan 2009
Posts: 16
Re: Array Functions in PHP

array_search ? Searches the array for a given value and returns the corresponding key if successful.

If needle is a string, the comparison is done in a case-sensitive manner.

Examples

PHP Code:
<?php
$array 
= array(=> 'blue'=> 'red'=> 'green'=> 'red');

$key array_search('green'$array); // $key = 2;
$key array_search('red'$array);   // $key = 1;
?>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Array Functions in PHP"
Thread Thread Starter Forum Replies Last Post
Components and functions of UML NatureAddicted Software Development 6 22-02-2011 03:47 PM
What are the PHP libxml Functions? taher Software Development 4 27-01-2010 10:07 PM
Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM
PHP fsockopen Functions Japesh Software Development 3 22-05-2009 06:02 PM
Functions in PHP Gyan Guru Guides & Tutorials 3 13-12-2008 06:20 PM


All times are GMT +5.5. The time now is 08:10 AM.