$value) { if ($i == 0) { $str .= $countarr[$value]; } else { $str .= '、' . $countarr[$value]; } $i++; } return $str; } /* * 提取数字并去数据库取得相应的分类名 * $strs 需要处理的字符串 * $table 数据表名 * $condition 条件字段 * $field 获取的字段 */ public function extractNumberGetNameForCondition($strs, $table, $condition, $field) { if (empty($strs)) { return ''; } $patterns = "/\d+/"; //第一种 preg_match_all($patterns, $strs, $arr); if (empty($arr[0])) { return ''; } $map[$condition] = array('in', $arr[0]); $map['status'] = DBCont::YES_BOOL_STATUS; $model = D($table); $result = $model->field($field)->where($map)->select(); $str = ''; $i = 0; foreach ($result as $key => $item) { if ($i == 0) { $str .= $item[$field]; } else { $str .= '、' . $item[$field]; } $i++; } return $str; } }