View Single Post
  #18 (permalink)  
Old 05-04-09, 02:10 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Okie. Met into some small problem. Would like to ask something.

I have this list.

Code:
// WarrantDateList
Array
(
    [2009-04-15] => Array
        (
            [0] => Name1
            [1] => Name1
            [2] => Name1
            [3] => Name1
            [4] => Name1
            [5] => Name1
        )

)

Array
(
    [2009-04-17] => Array
        (
            [0] => Name2
            [1] => Name2
            [2] => Name2
            [3] => Name2
            [4] => Name2
            [5] => Name2
        )

)
And what I wanted is to do a randomise selection of name in each array. I have the following code.

PHP Code:

function array_multi_rand($array) {

    
srand((float) microtime() * 10000000);
    
$Boo array_rand($array);
    if (
is_array($array[$Boo])) {
        return 
array_multi_rand($array[$Boo]);
    } else {
        return (
$array[$Boo]);
    }
}

// This is the code for me to randomise the array and get a name for each date.
// $gp = date
foreach ($gp as $GPS) {
    
$warrantDateList = array($GPS => $warrantList);
    
$inputGPduty[] .= array_multi_rand($warrantDateList);

Problem is that after I have done with array_multi_rand, it gives me this result.
Code:
// [0] suppose to be [2009-04-15] and [1] suppose to be [2009-04-17]
Array ( [0] => Name1 [1] => Name2 )
How can I do to the function so that the date remains as the key? Also, I would have to check if the values inside the array is the same. If it is, then I have to generate it again to get different value for each date.

Thanks.
Reply With Quote