1

Update : I've write my functions, and it works.

My Own Answer

<?php
function array_merge_recursive_random_static($first_array, $second_array, $key='')
{
    $merged_array = array_merge_recursive($first_array, $second_array);
    $arrays = &$merged_array;
    mt_srand(strlen($key)); 
    for ($i = count($arrays) - 1; $i > 0; $i--)
    { 
        $j = @mt_rand(0, $i); 
        $tmp = $arrays[$i]; 
        $arrays[$i] = $arrays[$j]; 
        $arrays[$j] = $tmp; 
    }
    return $arrays;
}
?>

My Own Question :

I have two arrays like this:

$array2 = array(
          0 => array('id' => 'dada', 'title' => 'this dada', 'desc' => 'dadaeating'),
          1 => array('id' => 'caca', 'title' => 'this caca', 'desc'=> 'caca eating') 
);

$array2 = array(
          0 => array('id' => 'baba', 'title' => 'this baba', 'desc' => 'baba eating'),
          1 => array('id' => 'memo', 'title' => 'this memo', 'desc'=> 'memo eating') 
);

I want merge $array1 and $array2 and make it static random unique, so I want my result like this :

$arrays = array(
          0 => array('id' => 'caca', 'title' => 'this caca', 'desc' => 'cacaeating'),
          2 => array('id' => 'memo', 'title' => 'this memo', 'desc'=> 'memo eating'),
          3 => array('id' => 'dada', 'title' => 'this dada', 'desc'=> 'dada eating'),
          4 => array('id' => 'baba', 'title' => 'this baba', 'desc'=> 'baba eating')
);

Everytime I reload page, output result always like result above.

2
  • static random unique... uh what? Commented Sep 15, 2011 at 7:04
  • I've found my answer :) yeah static random its useful for SEO, thanks Commented Sep 15, 2011 at 7:17

1 Answer 1

2

Just merge the arrays, then shuffle the resulting array.

$rand = array_merge($array1, $array2);
shuffle($rand);

$rand now contains the final version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.