標籤:io os 使用 ar for 資料 2014 on cti
//處理時間部分,將ISODate("2014-10-09T18: 37: 50.0Z") 轉換成 2014-10-09 18:37:50這種格式//最多處理6層樹形結構資料,當多維陣列中的key,包含數組$product_date_col中的任意一個字元,那麼就會被處理。public static function processMongoGetDate($product){foreach($product as $k1=>$v1){if(!is_array($v1)&& !is_object($v1)){}else{//if(self::contentDate($k1,$product_date_col)){if($v1->sec){$v1 = date('Y-m-d H:i:s', $v1->sec);}$product[$k1] = $v1;//}foreach($v1 as $k2=>$v2){if(!is_array($v2)&& !is_object($v2)){}else{//if(self::contentDate($k2,$product_date_col)){if($v2->sec){$v2 = date('Y-m-d H:i:s', $v2->sec);}$product[$k1][$k2] = $v2;//}foreach($v2 as $k3=>$v3){if(!is_array($v3)&& !is_object($v3)){}else{//if(self::contentDate($k3,$product_date_col)){if($v3->sec){$v3 = date('Y-m-d H:i:s', $v3->sec);}$product[$k1][$k2][$k3] = $v3;//}foreach($v3 as $k4=>$v4){if(!is_array($v4)&& !is_object($v4)){}else{//if(self::contentDate($k4,$product_date_col)){if($v4->sec){$v4 = date('Y-m-d H:i:s', $v4->sec);}$product[$k1][$k2][$k3][$k4] = $v4;//}foreach($v4 as $k5=>$v5){if(!is_array($v5)&& !is_object($v5)){}else{//if(self::contentDate($k5,$product_date_col)){if($v5->sec){$v5 = date('Y-m-d H:i:s', $v5->sec);}$product[$k1][$k2][$k3][$k4][$k5] = $v5;//}foreach($v5 as $k6=>$v6){if(!is_array($v6)&& !is_object($v6)){}else{//if(self::contentDate($k6,$product_date_col)){if($v6->sec){$v6 = date('Y-m-d H:i:s', $v6->sec);}$product[$k1][$k2][$k3][$k4][$k5][$k6] = $v6;//}}}}}}}}}}}}}return $product;}/* 作用:前端form傳遞過來的資料,無論儲存,還是查詢,都需要轉化成mongo的格式* 處理:處理的為,1.數字字串轉換成float類型,2.日期使用\MongoDate()轉換成mongo格式的日期。* 結果:此函數僅僅是轉換 欄位類型。最多為6層樹形結構表。*/public static function processMongoSetData($data,$float_array){//?gte ?lte$product = object_to_array($data);$productfloat = $float_array;foreach($product as $k1=>$v1){if(!is_array($v1)&& !is_object($v1)){if(in_array($k1,$productfloat)){if(is_numeric($v1)){$v1 = floatval($v1);$product[$k1] = $v1;}}if(is_time($v1)){$product[$k1] = new \MongoDate(strtotime($v1));}}else{foreach($v1 as $k2=>$v2){if(!is_array($v2)&& !is_object($v2)){if(in_array($k2,$productfloat)){if(is_numeric($v2)){$v2 = floatval($v2);$product[$k1][$k2] = $v2;}}if(is_time($v2)){$product[$k1][$k2] = new \MongoDate(strtotime($v2));}}else{foreach($v2 as $k3=>$v3){if(!is_array($v3)&& !is_object($v3)){if(in_array($k3,$productfloat)){if(is_numeric($v3)){$v3 = floatval($v3);$product[$k1][$k2][$k3] = $v3;}}if(is_time($v3)){$product[$k1][$k2][$k3] = new \MongoDate(strtotime($v3));}}else{foreach($v3 as $k4=>$v4){if(!is_array($v4)&& !is_object($v4)){if(in_array($k4,$productfloat)){if(is_numeric($v4)){$v4 = floatval($v4);$product[$k1][$k2][$k3][$k4] = $v4;}}if(is_time($v4)){$product[$k1][$k2][$k3][$k4] = new \MongoDate(strtotime($v4));}}else{foreach($v4 as $k5=>$v5){if(!is_array($v5)&& !is_object($v5)){if(in_array($k5,$productfloat)){if(is_numeric($v5)){$v5 = floatval($v5);$product[$k1][$k2][$k3][$k4][$k5] = $v5;}}if(is_time($v5)){$product[$k1][$k2][$k3][$k4][$k5] = new \MongoDate(strtotime($v5));}}else{foreach($v5 as $k6=>$v6){if(!is_array($v6)&& !is_object($v6)){if(in_array($k6,$productfloat)){if(is_numeric($v6)){$v6 = floatval($v6);$product[$k1][$k2][$k3][$k4][$k5][$k6] = $v6;}}if(is_time($v6)){$product[$k1][$k2][$k3][$k4][$k5][$k6] = new \MongoDate(strtotime($v6));}}else{}}}}}}}}}}}}return $product;}
mongodb - 前端form表單傳遞資料,在儲存和取出的資料格式處理函數 - 非遞迴