PHP 7.2.0 Beta 1 Released

Voting

Please answer this simple SPAM challenge: min(two, seven)?
(Example: nine)

The Note You're Voting On

shooo dot xz at gmail dot com
3 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