search

Home  >  Q&A  >  body text

How to loop through two or more arrays in php or jq, each array has two elements, as shown below

For example: $a = [A,B] $b = [C,D]

How to loop $array=array(

,

                                                                                                                                                                                            ) ,

                                                   

God help me! ! The method that is not hard-coded can be multiple arrays. The background product specifications are as follows, both js and php can be used

何惜一博何惜一博2247 days ago1197

reply all(3)I'll reply

  • 唯一

    唯一2018-11-20 10:00:14

    Multiple specifications

    reply
    0
  • PHP

    PHP2018-11-16 17:57:40

    <?php

    $arr = array();

    foreach($a as $key=>$value){

        foreach($b as $key1=>$value1){

            $arrSon[] = $value;

            $arrSon[] = $value1;

            $arr[] = $arrSon;

            unset($arrSon);

        }

    }

    echo "<pre/>";

    print_r($arr);

    ?>

    希望有用

    reply
    0
  • 何惜一博

    Brother, what if there are three or four groups, such as $a = [A,B] $b = [C,D] $c = [E,F] $array=array( array(A,C,E) , array(A,C,F) , array(A,D,E), array(A,D,F) , ..... array(B,D,F) ) The loop reaches the end, is there any way, brother?

    何惜一博 · 2018-11-16 18:03:59
  • Cancelreply