Convert java code to PHP code

Source: Internet
Author: User
Java code to PHP code, master into importjava. util. ArrayList; importjava. util. Arrays; importjava. util. List; publicclassArrayAssemble {@ SuppressWarnings (java code to PHP code, master
Import java. util. arrayList; import java. util. arrays; import java. util. list; public class ArrayAssemble {@ SuppressWarnings ("unchecked") public static void main (String [] args) {String [] arrOfInt = {"red", "Orange ", "Yellow", ""}; @ SuppressWarnings ("unused") String [] arrOfChar1 = {"L", "XL"}; @ SuppressWarnings ("unused ") string [] arrOfChar2 = {"hemp", "acrylic", ""}; String [] arrOfChar3 = {"Kui", "Kang "}; string [] arrOfStr = {"lmy", "lyb", "mz", "yx"}; System. out. println ("The following is the Combined Array"); // Object [] [] objectsArrays = assembleArraysToPlanerArray (new Object [] [] {arrOfInt, arrOfChar1, arrOfChar2, arrOfChar3, arrOfStr}); Object [] [] objectsArrays = assembleArraysToPlanerArray (new Object [] [] {arrOfChar1, arrOfChar2, arrOfChar3 }); // Object [] [] objectsArrays = assembleArraysToPlanerArray (new Object [] [] {arrOfChar1, arrOfChar2}); int I = 0; for (Object [] objArrays: objectsArrays) {I ++; System. out. println (I + "=" + Arrays. toString (objArrays);} // method 1 auxiliary method: combines a List of array or object types with an array, and returns List @ SuppressWarnings ("unchecked ") public static List assembleArrayToList (List aList, Object [] array) {List arrList = new ArrayList (); // traverses aList and combines array with aList for (int I = 0; I <aList. size (); I ++) {Object obj = aList. get (I); // check whether the aList element is of the array type. if not, the combination list if (obj instanceof Object []) is directly generated. {Object [] listArr = (Object []) obj; // combines array-type aList elements with arrays for (int k = 0; k <array. length; k ++) {Object [] newListArr = new Object [listArr. length + 1]; for (int j = 0; j <listArr. length; j ++) {newListArr [j] = listArr [j];} newListArr [listArr. length] = array [k]; arrList. add (newListArr) ;}} else {// combines non-array aList elements with arrays for (int j = 0; j <array. length; j ++) {Object [] arrObj = {aList. get (I), array [j]}; arrList. add (arrObj) ;}}return arrList;} // Method 2: return the two-dimensional array type of the combination using the two-dimensional array parameter method, and use recursive @ SuppressWarnings ("unchecked ") public static Object [] [] assembleArraysToPlanerArray (Object [] [] objectArrays) {if (objectArrays. length = 2) {Object [] assembledArray = objectArrays [0]; Object [] array = objectArrays [1]; return assembleArrayToArray (assembledArray, array);} else if (objectArrays. length <= 1) {return objectArrays;} else {Object [] objArray = objectArrays [objectArrays. length-1]; objectArrays = Arrays. copyOf (objectArrays, objectArrays. length-1); return assembleArrayToArray (assembleArraysToPlanerArray (objectArrays), objArray) ;}// method 2 auxiliary method: combines an array or two-dimensional array type with an array, returns the two-dimensional array public static Object [] [] assembleArrayToArray (Object [] assembledArray, Object [] array) {int lenAssArray = assembledArray. length; int lenArray = array. length; Object [] [] objArrays = new Object [lenAssArray * lenArray] []; for (int I = 0; I <lenAssArray; I ++) {Object obj = assembledArray [I]; if (obj instanceof Object []) {Object [] objArr = (Object []) obj; int lenObjArr = objArr. length; for (int k = 0; k <lenArray; k ++) {// Copy the objArr array to the newListArr array and add its length to the Object [] newListArr = Arrays. copyOf (objArr, lenObjArr + 1); // assign the k + 1 element of the array to the last element of the newListArr array, assign newListArr to newListArr [lenObjArr] = array [k]; objArrays [lenArray * I + k] = newListArr ;}} else {for (int j = 0; j <lenArray; j ++) {Object [] newObjArray = {obj, array [j]}; objArrays [lenArray * I + j] = newObjArray ;}}return objArrays ;}}

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.