最近開始寫PHP項目,各類經常使用的方法簡單整理一下,以備後用。html
1. Xml轉Json算法
json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true)
2. Request請求封裝json
3. RSA加密解密算法數組
4. AES加密解密算法post
5. 數組轉字符串&拼接ui
public function build_query($data){ $str=''; if(is_array($data)){ ksort($data); foreach ($data as $key=>$value){ $str .= (empty($str) ? '' : '&' ) . $key . '=' . (is_array($value) ? '(' .self::build_query($value). ')' : $value); } } return $str; }