Javascript-[algorithm] how to implement random key-value pairs in the array with the first place?

Source: Internet
Author: User
For example, the final effect of {code...} is as follows: {code...}. how can this algorithm be implemented? Example:

$ Arr = array ('000000' => 'flammulina velutipes ''000000' => 'Silver mushroom '); $ arr2 = array ('65' => 'white radish '67' => 'Black radish '84' => 'yellow radish '100' => 'Silver mushroom'' 90' => 'radish '000000' => 'mushroom ');

The final effect is as follows:

$ Arr3 = array ('20140901' => 'flammulina velutipes '20160301' => 'Silver needle mushroom '65' => 'white radish '67' => 'Black radish'' 84 '=> 'radish '90' => 'radish ');

How can this algorithm be implemented?

Reply content:

Example:

$ Arr = array ('000000' => 'flammulina velutipes ''000000' => 'Silver mushroom '); $ arr2 = array ('65' => 'white radish '67' => 'Black radish '84' => 'yellow radish '100' => 'Silver mushroom'' 90' => 'radish '000000' => 'mushroom ');

The final effect is as follows:

$ Arr3 = array ('20140901' => 'flammulina velutipes '20160301' => 'Silver needle mushroom '65' => 'white radish '67' => 'Black radish'' 84 '=> 'radish '90' => 'radish ');

How can this algorithm be implemented?

The problem has been closed and I wrote it myself. I thought it was complicated when I asked the question. after the problem was solved, I realized it was so simple that I posted the code:

foreach ($arr2 as $key => $value) {    if(!in_array($value, $arr)) {        $arr[$key] = $value;    }}var_dump($arr);

return($arr + $arr2);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.