function implode_r($glue, $array, $array_name = NULL) { $return = array(); while (list($key, $value) = @each($array)) { if (is_array($value)) { $return[] = implode_r($glue, $value, (string) $key); } else { if ($array_name != NULL) { $return[] = $array_name . "[" . (string) $key . "]=" . $value . "\n"; } else { $return[] = $key . "=" . $value . "\n"; } } } return implode($glue, $return); }
function implode_r($glue, $pieces, $extract_first_item = false) { $result = array_shift($pieces); if (is_array($result)) { $result = implode_r($glue, $result); } foreach ($pieces as $item) { if (is_array($item)) { $result .= empty($extract_first_item) ? implode_r($glue, $item) : $glue . $item[0]; } else { $result .= $glue . $item; } } return $result; }
function implode_r($glue, $pieces) { $out = ''; foreach ($pieces as $piece) { if (is_array($piece)) { if ($out == '') { $out = implode_r($glue, $piece); } else { $out .= implode_r($glue, $piece); // recurse } } else { if ($out == '') { $out .= $piece; } else { $out .= $glue . $piece; } } } return $out; }
/** * 将数据转化成字符串 * @params array $glue 连接符 * @params array $pieces 要转化的数组 * @return string 返回转化后的字符串 */ function implode_r($glue, $pieces) { $return = ""; if (!is_array($glue)) { $glue = array($glue); } $thisLevelGlue = array_shift($glue); if (!count($glue)) { $glue = array($thisLevelGlue); } if (!is_array($pieces)) { return (string) $pieces; } foreach ($pieces as $sub) { $return .= implode_r($glue, $sub) . $thisLevelGlue; } if (count($pieces)) { $return = substr($return, 0, strlen($return) - strlen($thisLevelGlue)); } return $return; }
function implode_r($glue, $array, $format = '(%s)') { if (!is_array($array)) { $array[0] = $array; } $out = ''; foreach ($array as $item) { if (is_array($item)) { $out .= sprintf($format, implode_r($glue, $item)); } else { if ($out) { $out .= $glue; } $out .= print_r($item, true); } } return $out; }
/** * Upgraded implode($glue, $arr) function that * do not aggregate NULL elements in result */ public static function superImplode($glue, $arr) { $ret_str = ""; foreach ($arr as $a) { $ret_str .= is_array($a) ? implode_r($glue, $a) : $a === NULL ? "" : strval($a) . $glue; } if (strrpos($ret_str, $glue) != strlen($glue)) { $ret_str = substr($ret_str, 0, -strlen($glue)); } return $ret_str; }
/** * parse_w 解析条件数组 * @param int $OrgID 标识ID * @param array $Where 条件数据 * @return array 返回解析后的条件数据 */ private function parse_w($OrgID, $Where) { $LeadAttr = $this->attr->object_attr(1, NULL); extract($Where, EXTR_OVERWRITE); //释放数组数据 where rel $sql_w = array(); $obj_data = $this->obj->ObjParseData($this->obj->NameGetObj(1, NULL, TRUE)); for ($i = count($where); $i > 0; $i--) { $rel = str_replace($i, "rel_" . $i, $rel); } foreach ($where as $k => $v) { $attr_values = ConverArray($v['attr'], '.'); $s_attr_values = $attr_values; //判断传进来的数据是否是正常可以查询,如果不是则需要做再次判断,先判断第一个键值是否与当前模块类型相等如果不等则是外部引用 //Lead.Owner.Name if (count($attr_values) > 2) { $this->parseAttr($LeadAttr, $obj_data, $attr_values, $v, $sql); $res_data = $this->db->query($sql)->result_array(); $str_values = implode_r(array(","), $res_data); $fld = $LeadAttr[$LeadAttr[$s_attr_values[0] . "." . $s_attr_values[1]]['referred_by']]['fld_name']; $v['value'] = $str_values; $v['action'] = 'INC'; //此处明天继续 } else { $fld = $LeadAttr[$v["attr"]]['fld_name']; if (empty($fld)) { $attr_values = $LeadAttr[$v["attr"]]; if ($attr_values["attr_type"] == 4 && $attr_values["is_ref_obj"] == 1) { $fld = $LeadAttr[$LeadAttr[$v["attr"]]["referred_by"]]["fld_name"]; } } } switch ($v['action']) { case 'NULL': //为空 同is null $w = $fld . ' IS NULL'; break; case 'NOT_NULL': //不为空 同is not null $w = $fld . ' IS NOT NULL'; break; case 'NOT_EQUAL': //不等于 同<> $w = $fld . ' != \'' . $v['value'] . '\''; break; case 'GT': //大于 同> $w = $fld . ' > \'' . $v['value'] . '\''; break; case 'GT_EQUAL': //大于等于 同>= $w = $fld . ' >= \'' . $v['value'] . '\''; break; case 'LE': //小于 同< $w = $fld . ' < \'' . $v['value'] . '\''; break; case 'EQUAL': //等于 同= $equal_value = isset($v['value']) ? $v['value'] : $v['value2']; $w = $fld . ' = \'' . $equal_value . '\''; break; case 'LE_EQUAL': //小于等于 同<= $w = $fld . ' <= \'' . $v['value'] . '\''; break; case 'INC': //涵盖 同in $v['value'] = str_replace(',', '\',\'', $v['value']); $w = $fld . ' IN(\'' . $v['value'] . '\')'; break; case 'NOT_INC': //不涵盖 同not in $v['value'] = str_replace(',', '\',\'', $v['value']); $w = $fld . ' NOT IN(\'' . $v['value'] . '\')'; break; case 'RANGE': //区间 同>= and <= if (preg_match("/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/", $v['value2'])) { //是日期时间类型,给成 23:59:59 if (strlen($v['value2']) <= 10 and strlen($v['value2']) >= 8) { $v['value2'] = $v['value2'] . " 23:59:59"; } } $w = $fld . ' >=' . "to_date('" . $v['value1'] . "', 'yyyy-mm-dd hh24:mi:ss')" . ' AND ' . $fld . ' <= ' . "to_date('" . $v['value2'] . "', 'yyyy-mm-dd hh24:mi:ss')"; break; case 'LIKE': $w = $fld . " LIKE '%" . $v['value'] . "%'"; break; case 'NOT_LIKE': //不包含 同not like $w = $fld . " NOT LIKE '%" . $v['value'] . "%'"; break; case 'BEFORE': //早于,用于日期时间类型 $w = $fld . " < " . "to_date('" . $v['value'] . "', 'yyyy-mm-dd hh24:mi:ss')" . ""; break; case 'AFTER': //晚于,用于日期时间类型 $w = $fld . " > " . "to_date('" . $v['value'] . "', 'yyyy-mm-dd hh24:mi:ss')" . ""; break; case 'RECENT': //最近,用于日期时间类型 $w = $fld . " >= " . "to_date('" . date("Y-m-d H:i:s", strtotime("-{$v['value1']} {$v['value2']}")) . "', 'yyyy-mm-dd hh24:mi:ss')" . ""; break; case 'FUTURE': //未来,用于日期时间类型 $w = $fld . " >= " . "to_date('" . date("Y-m-d H:i:s", strtotime("+{$v['value1']} {$v['value2']}")) . "', 'yyyy-mm-dd hh24:mi:ss')" . ""; break; case '1': $w = " 1 = 1 "; break; default: $w = $fld . ' = \'' . $v['value'] . '\''; break; } if (!empty($w)) { $sql_w[$k] = $w; $rel = str_replace("rel_" . $k, $w, $rel); } } return $rel; }
function implode_r($glue, array $arr) { $ret = ''; foreach ($arr as $piece) { if (is_array($piece)) { $ret .= '; ' . implode_r($glue, $piece); } else { $ret .= $glue . $piece; } } return $ret; }