<?php
$testArray = array('foot', 'bike', 'car', 'plane');
next($testArray); next($testArray);
echo prev($testArray); // bike
?>
<?php
$testArray = array('foot', 'bike', 'car', 'plane');
echo current($testArray); // foot
?>
<?php
$testArray = array('foot', 'bike', 'car', 'plane');
secho next($testArray); // bike
?>
<?php
$testArray = array("key1" => "Value1","key2" => "Value2","key3" => "Value3");
$testArray = array_flip($testArray);
print_r($testArray);
//Array ( [Value1] => key1 [Value2] => key2 [Value3] => key3 )
?>
<?php
$testArray = array(5, 3, 8, 10);
echo "Sum is : ".array_sum($testArray) ;
//Sum is : 26
?>
<?php
$search_array = array('key1' => 17, 'key2' => 74);
if (array_key_exists('key1', $search_array)) {
echo "The key 'key1' exists ";
}
//The key 'key1' exists
?>
<?php
$testArray=array("Value1","Value1","Value1","Value2");
print_r(array_count_values($testArray));
//Array ( [Value1] => 3 [Value2] => 1 )
?>
<?php
$testArray1 = array('key1', 'key2', 'key3');
$testArray2 = array('value1', 'value2', 'value3');
$testArray3 = array_combine($testArray1, $testArray2);
print_r($testArray3);
//Array ( [key1] => value1 [key2] => value2 [key3] => value3 )
// NOTE : Make sure that the 2 arrays have equual
// number of elements
?>
<?php
$testArray1 = array("place" => "kochi", 11, 12);
$testArray2 = array("p", "s", "place" => "Tvm", "Width" => "10", 84);
$testArray3 = array_merge($testArray1, $testArray2);
print_r($testArray3);
//Array ( [place] => Tvm [0] => 11 [1] => 12 [2] => p [3]
//=> s [Width] => 10 [4] => 84 )
?>
<?php
$testArray = array("Value1","Value2", "Value3");
print_r(array_map('strtoupper', $testArray));
// Array ( [0] => VALUE1 [1] => VALUE2 [2] => VALUE3 )
?>
Zend | Magento Certified PHP | eCommerce Architect