Write a piece of code in PHP

Source: Internet
Author: User
Thank you for your enthusiastic reply. Sorry, I didn't make it clear when I described the problem, which delayed your time. For example, the word "Chongqing", because the word "heavy" is a multi-tone word, reads: C, Z; and "Qing: Q should combine all the pronunciations: CQ, ZQ, "...

Thank you for your enthusiastic reply. Sorry, I didn't make it clear when I described the problem, which delayed your time.

For example:
The word "Chongqing", because the word "heavy" is a multi-tone word, reads: C, Z; and the word "Qing", reads: Q to combine all the pronunciations: CQ, ZQ
So,
In this case, the CQC, ZQC, CQZ, and ZQZ pronunciation should be combined.

Then more words are combined into more combinations.

How can this problem be achieved?

$arr = array('a','b');$single = array('c','b');function merge(){    $arg = func_get_args();    $r = array();    if(0 < count($arg) && is_array($arg[0])){        $base = $arg[0];        foreach ($arg as $k => $v) {            if($k > 0 && is_array($v)){                foreach($base as $sk=>$sv){                    foreach ($v as $tk => $tv) {                        array_push($r, $sv.$tv);                    }                }            }        }        if(0 < count($r)){            return $r;        }else{            return !1;        }    }else{        return !1;    }}var_dump(merge($arr, $single));

Reply content:

Thank you for your enthusiastic reply. Sorry, I didn't make it clear when I described the problem, which delayed your time.

For example:
The word "Chongqing", because the word "heavy" is a multi-tone word, reads: C, Z; and the word "Qing", reads: Q to combine all the pronunciations: CQ, ZQ
So,
In this case, the CQC, ZQC, CQZ, and ZQZ pronunciation should be combined.

Then more words are combined into more combinations.

How can this problem be achieved?

$arr = array('a','b');$single = array('c','b');function merge(){    $arg = func_get_args();    $r = array();    if(0 < count($arg) && is_array($arg[0])){        $base = $arg[0];        foreach ($arg as $k => $v) {            if($k > 0 && is_array($v)){                foreach($base as $sk=>$sv){                    foreach ($v as $tk => $tv) {                        array_push($r, $sv.$tv);                    }                }            }        }        if(0 < count($r)){            return $r;        }else{            return !1;        }    }else{        return !1;    }}var_dump(merge($arr, $single));

Use a function:

The meaning of your image: a large array contains two small arrays, and now the third array is given, which is combined into each small array of the large array.

Implementation principle:

Array merging and returning a new array function: array_merge ().

Function merge ($ a1, $ a2, $ a3 ){
$ Result = array ();
$ T1 = arrar_merge ($ a1, $ a3 );
$ T2 = arrar_merge ($ a2, $ a3 );
$ Result [] = $ t1;
$ Result [] = $ t2;
Return $ result;
}


   $item) {        $arr[$key][0] = $arr[$key][0].$single[0];    }    var_dump($arr);

$ Answer = array_map (function ($ subArray) use ($ third) {return array_merge ($ subArray, $ third) ;}, $ first );
Do not blame?

Related Article

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.