Exemplo n.º 1
0
 public static function collection_select_options($table, $value, $options = array())
 {
     if (is_string($options)) {
         $options = array('order' => $options);
     }
     $options += array('key' => 'id', 'select' => '*');
     $sql = "SELECT {$options['select']} FROM {$table}";
     if (isset($options['where'])) {
         $sql .= " WHERE {$options['where']}";
     }
     if (isset($options['order'])) {
         $sql .= " ORDER BY {$options['order']}";
     }
     $res = \GDB::instance()->q($sql)->key($options['key']);
     if (is_string($value)) {
         $res->mode('value', $value);
         return $res->stack();
     } else {
         return kmap($res, $value);
     }
 }
Exemplo n.º 2
0
 public function test_kmap()
 {
     assert_equal(array('a' => 2, 'b' => 4, 'c' => 6), kmap(array('a' => 1, 'b' => 2, 'c' => 3), function ($v) {
         return $v * 2;
     }));
 }