Làm cách nào để tạo trong PHP tất cả các tổ hợp mục trong nhiều mảng?

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
1

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
3

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
4

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
5

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
6

Chúng tôi được yêu cầu viết một hàm JavaScript có hai mảng chữ như vậy. Sau đó, hàm sẽ kết hợp từng phần tử của mảng đầu tiên với từng phần tử của mảng thứ hai và đẩy chúng vào một mảng mới

Do đó, đầu ra cho đầu vào ở trên sẽ trông như thế này -

const output = ["A1","A2","A3","B1","B2","B3","C1","C2","C3"];

Ví dụ

Mã cho điều này sẽ là -

const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];

đầu ra

Và đầu ra trong bảng điều khiển sẽ là -

[
   'A1', 'A2', 'A3',
   'B1', 'B2', 'B3',
   'C1', 'C2', 'C3'
]

Lần lặp đầu tiên cho biết cùng một bộ ký tự sẽ được hiển thị. Nếu kích thước là 1, thì sự kết hợp được hiển thị. Một mảng được khởi tạo là 'new_combinations' và nó được lặp lại bằng cách sử dụng 'forloop' và mọi ký tự trong chuỗi đó được nối với mọi ký tự khác. Hàm 'lấy mẫu' được gọi với các tham số [chuỗi, kích thước của chuỗi và mảng]

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
0
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
1
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
3
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
5

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
6
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
8
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
30

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
6
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
33
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
35

 

const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
36

const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
37

const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
38

const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
39

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
0
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
1
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
3
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
5
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
7

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
8

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
70

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
72

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
75

 

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
77

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
79

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
21

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
22

 

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
23

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
24

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
25

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
26

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
27

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
28

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
29

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
0
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
1
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
3
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
5

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
6
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
8
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
30

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
6
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
const arr1 = ["A","B","C"];
const arr2 = ["1","2","3"];
const prepareCartesian = [arr1 = [], arr2 = []] => {
   const res = [];
   for[let i = 0; i < arr1.length; i++]{
      for[let j = 0; j < arr2.length; j++]{
         res.push[arr1[i] + arr2[j]]
      }
   };
   return res;
};
console.log[prepareCartesian[arr1, arr2]];
33
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
2
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
7

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
8

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
18

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
20

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
22
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
23

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
9
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
8

        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
26
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
27
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
28
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
265
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
266
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
265
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
268
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
191
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
34
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
265
        // Since the elements are sorted, all occurrences of an element
        // must be together
        while [arr[i] == arr[i+1]]
             i++; 
272

+= có hoạt động trên các mảng trong PHP không?

Toán tử + trong PHP khi được áp dụng cho mảng sẽ thực hiện công việc của mảng UNION . mảng $arr += mảng $arr1; .

Hàm nào bắt đầu nhiều mảng cùng một lúc trong PHP?

Hàm array_merge[] trong PHP

Làm cách nào tôi có thể lấy hai dữ liệu từ cùng một mảng trong PHP?

Hàm array_intersect[] so sánh giá trị của hai [hoặc nhiều] mảng và trả về kết quả khớp. Hàm này so sánh các giá trị của hai hoặc nhiều mảng và trả về một mảng chứa các mục từ mảng1 có trong mảng2, mảng3, v.v.

Chủ Đề