Re: [PHP] array conversion

2010-02-20 Thread clancy_1
Or: $a = array ('Cats', 'white', 'Dogs', 'black', 'Mice', 'grey', 'Camels', 'brown'); $b = '';// Just in case it has some leftover value $k = 2* (int) (count ($a)/2); // ensure even no of terms $i = 0; while ($i < $k) { $b[$a[$i++]] = $a[$i++];

Re: [PHP] array conversion

2010-02-19 Thread Richard Quadling
On 19 February 2010 15:52, tedd wrote: > At 10:48 AM + 2/19/10, Richard Quadling wrote: >> >> On 19 February 2010 07:26, Adam Richardson wrote: >>  Or, > > Code fight!!! > > http://www.webbytedd.com/ccc/array/ > > After reviewing the entries, mine does not provide any significant > difference

Re: [PHP] array conversion

2010-02-19 Thread tedd
At 10:48 AM + 2/19/10, Richard Quadling wrote: On 19 February 2010 07:26, Adam Richardson wrote: Or, Code fight!!! http://www.webbytedd.com/ccc/array/ After reviewing the entries, mine does not provide any significant difference. I did it as a mental exercise after looking at several

Re: [PHP] array conversion

2010-02-19 Thread Richard Quadling
On 19 February 2010 07:26, Adam Richardson wrote: > Or, > > function new_arr(array $arr) > { >    $count = count($arr); >    if ($count % 2 != 0) throw new Exception('The new_arr() function > requires an even number of elements.'); >    for ($i = 0; $i < $count; $i += 2) >    { >        $new_arr[$

Re: [PHP] array conversion

2010-02-18 Thread Adam Richardson
Or, function new_arr(array $arr) { $count = count($arr); if ($count % 2 != 0) throw new Exception('The new_arr() function requires an even number of elements.'); for ($i = 0; $i < $count; $i += 2) { $new_arr[$arr[$i]] = $arr[$i + 1]; } return $new_arr; } $test = ne

Re: [PHP] array conversion

2010-02-18 Thread Larry Garfield
On Thursday 18 February 2010 11:58:28 pm Paul M Foster wrote: > On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote: > > Hi guys. How to convert an array like: > > > > Array > > ( > > [0] => key1 > > [1] => value1 > > [2] => key2 > > [3] => value2 > > ) > > > > to > > > > > > Array

Re: [PHP] array conversion

2010-02-18 Thread Paul M Foster
On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote: > Hi guys. How to convert an array like: > > Array > ( > [0] => key1 > [1] => value1 > [2] => key2 > [3] => value2 > ) > > to > > > Array > ( > [key1] => value1 > [key2] => value2 > ) > > Is there a built-in function to

Re: [PHP] Array conversion

2003-05-30 Thread Ernest E Vogelsinger
At 01:38 30.05.2003, John Wulff said: [snip] >I'm new to working with complex arrays/objects and need a little help. >Below is the array I need to convert to a different type of array. The >"begin what i have" section is data I've succesfully mined from an X