According to the idea, the php recursive function returns a two-dimensional array with two values using a test array. But it is worth reading an array. isn't it possible to write the red part like this? How should I write it? Solution ==================================== the code is as follows ==== ====== php recursive function solution
Originally, according to the idea, the recursive function returns a two-dimensional array with two values using a test array. But it is worth reading an array. isn't it possible to write the red part like this? How should I write it? Solution
==================================== The code is as follows: ========================================================== ======================
$ Strr = array ("Thursday 301 _ Phoenix Mercury _ Chicago Sky _ main victory _ 2.10", "Tuesday 302 _ Minnesota bobcat _ Indiana fanatic _ main victory _ 1.20 ", "Tuesday 302 _ Minnesota bobcat _ Indiana fanatic _ Kewin _ 2.92 ");
// This is the way to split the array -----
Function A ($ str ){
// Define a two-dimensional array to store the logically separated array
$ Newstr = array ();
For ($ I = 0; $ I $ E1 = explode ("_", $ str [$ I]);
$ E2 = explode ("_", $ str [$ I + 1]);
If ($ e1 [0]. $ e1 [1]. $ e1 [2] = $ e2 [0]. $ e2 [1]. $ e2 [2]) {
// Split the string into two arrays and call A ($ str) recursively)
A (array_splice ($ str, $ I, $ I ));
A (array_splice ($ str, $ I + 1, $ I + 1 ));
}
}
Array_push ($ newstr, $ str );
Return $ newstr;
}
//------------------------
$ Back = A ($ strr );
Print_r ($ back );
?>
========================================================== ========================================================== ======================================
------ Solution --------------------
No recursion is needed
PHP code
$ Oddses) {// $ newList [] = array (); $ newList = _ combinate ($ newList, $ oddses);} return $ newList ;} function _ combinate ($ arr, $ newItems) {$ newArr = array (); if (empty ($ arr) {foreach ($ newItems as $ item) {$ newArr [] = array ($ item);} return $ newArr;} foreach ($ newItems as $ newItem) {foreach ($ arr as $ oldItems) {$ oldItems [] = $ newItem; $ newArr [] = $ oldItems;} return $ newArr;} echo''; Print_r (B ($ strr); exit;
------ Solution --------------------
It's just that your data is not suitable. just sort the order.
I don't know what you want to do! Just guess your thoughts based on your code. If you leave your overall idea, it will be meaningless.
PHP code
$ Str_2 = array ("a_a_a_1", "a_a_a_2", "B _ B _ B _1", "B _ B _ B _ B _2", "c_c_c_1", "a_a_a_3 "); // ------------------------ $ back = A ($ str_2); print_r ($ back); // This is the method for splitting arrays ----- function A ($ str) {sort ($ str ); // sort and put the similarity together. // define a two-dimensional array to store the array $ newstr = array (); for ($ I = 0; $ I