php - Can I use PDO::FETCH_GROUP to group results by two values -
I am using PHP and PDO to recover a set of values from a database and then from the first column to the group Code with this: It comes back in this form: How do I group the columns by column 1 and column 2, so I get something: Is it possible to do this with a combination of PDO constants? Thank you As you've seen, it's easy to easily arrange an array Grouping with code with You need this to manually do it manually through the nested loop, such as: Here returns: And it looks like you. $ result = $ sth- & gt; Get All (PDO :: FETCH_GROUP | PDO :: FETCH_NUM); This means that if my data is in this format:
| Column1. Column2. Column 3 | 1 | 2 | One | | 1 | 2 | B
1: {[column2: 2, column3: a], [Column 2: 2, Column 3: B]}
1: {2: { Column3: a, Column3: b}}
PDO :: FETCH_GROUP can be easy. What needs to be done is to convert the 2-dimension array into a 3-dimensional array, but it is not possible to rebuild it this way.
// Assume that the result of $ is: $ Result = [[1, 2, 'a'], [1, 2, 'b']]; $ newResult = []; Foreign Currency ($ $ as result of $) {$ newResult [$ line [0]] [$ row [1]] [] = $ line [2]; } Var_dump ($ newResult);
array (1) {[1] = & gt; Array (1) {[2] = & gt; Array (2) {[0] = & gt; String (1) "a" [1] = & gt; String (1) "b"}}}
Comments
Post a Comment