Voting

: eight plus one?
(Example: nine)

The Note You're Voting On

shooo dot xz at gmail dot com
10 years ago
Hi, i've worked a abit on reference stuff.
Here is what i've noticed.

The problem: Sort mysql result through columns

$rewrite_self = gt::recombine(array('lang', 'id'), 'value_column', $sql_result);

public static function recombine($keys, $value, &$arr) {
$ref = array();
$main = &$ref;
foreach($arr as $data) {
foreach($keys as $key) {
if (!is_array($ref[$data[$key]])) $ref[$data[$key]] = array();
$ref = &$ref[$data[$key]];
}
$ref = $data[$value];
$ref = &$main;
}
return $main;
}

array(2) {
["pl"]=>
array(2) {
[2]=>
string(4) "value_column_str"
[3]=>
string(4) "value_column_str2"
}
["en"]=>
array(1) {
[13]=>
string(7) "value_column_str3"
}
}

Enjoy!

<< Back to user notes page

To Top