示例#1
0
文件: helpers.php 项目: jaz303/zing
 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);
     }
 }
示例#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;
     }));
 }