View Single Post
  #5 (permalink)  
Old 04-18-2008, 03:21 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,159
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Operations in PHP

Combine an array with data elements and other with its keys

We can create an array by combining one array with keys and second array with corresponding data elements. Note that the number of keys and data elements in both the arrays has to be equal for this operation to be successful. We will make use of built-in function array_combine(). Its syntax is:
array_combine ( array keys, array values )

and the example using array_combine() is:
PHP Code:
<?
$keys_array 
= array(1,2,3,4);
$data_array = array("one","two","three","four");
$new_array array_combine($keys_array$data_array);
print_r($new_array);
//Output: Array
// (
//     [1]  => one
//     [2]  => two
//     [3]  => three
//     [4]  => four
// )
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Reply With Quote