数组转字符串

@param      $array
@param bool $isUrl

@return string
544784
public static function arrayToStr($array, $isUrl = true)
    {
        if($isUrl){
            $return = http_build_query($array);
        }else{
            $params = [];

            foreach($array as $key => $val){
                $params[] = $key . '=' . $val;
            }

            $return = join("&", $params);
        }

        return $return;
    }
235739
protected function getArrayAsText($array, $intendBy=1)
    {
        $intention = '';
        for ($i=0; $i<$intendBy; $i++) {
            $intention .= '    ';
        }

        $text = var_export($array, true);

        $text = preg_replace('/[ ]{2}/', '    ', $text);
        $text = preg_replace("/\=\>[ \n    ]+array[ ]+\(/", '=> array(', $text);
        return $text = preg_replace("/\n/", "\n".$intention, $text);
    }
373703
public function getUrl(array $data = []) {
        // Guess the what URL should be looked like
        $translation_guess = preg_replace(['/\[([^\[]+)\]/is', '/{(\w*?)}/is', '/{(\w*?):(:?.*?)}/is'], '{$1}', $this->_path);
        
        $keys = [];
        preg_match_all('/{(\w*?)}/is', $translation_guess, $keys);

        foreach ($keys[1] as $key) {
            $translation_guess = str_replace('{'.$key.'}', isset($data[$key]) ? $data[$key] : 'null', $translation_guess);
        }

        // Get raw pattern from route
        $translation = preg_replace(['/\//is', '/\[([^\[]+)\]/is', '/{(\w*?)}/is'],['\/', '(?:$1)?', '{$1:([^\/]+)}'], $this->_path);
        $keyex = [];
        preg_match_all('/{(\w*?):(.*?)}/', $translation, $keyex);
        $groups = array_map(function($val) {
            return '(' . trim(trim($val, ')'), '(') . ')';
        }, $keyex[2]);
        $translation = str_replace($keyex[0], $groups, $translation);

        // Check if guess is valid
        $test = preg_match("#^$translation$#is", $translation_guess, $vals);

        return $test ? $translation_guess : '';
    }
568641
public function urlencode_array(array $ar) {
		$datastring = '';
		foreach ($ar as $key => $val) {
			if (!empty($datastring)) {
				$datastring .= '&';
			}
			$datastring .= urlencode($key).'='.urlencode($val);
		}
		return $datastring;
	}
103782
protected function _getSession($array = []) {
        if (isset($_SESSION['' . $array[0] . ''])) {
            $to = $_SESSION['' . $array[0] . ''];
            array_splice($array, 0, 1);

            foreach ($array as $value) {
                if (isset($to['' . $value . ''])) {
                    $to = $to['' . $value . ''];
                }
                else {
                    return false;
                }
            }
        }
        else {
            return false;
        }

        return $to;
    }
877652
protected static function readArray(array $array): string
    {
        $data = [];

        foreach ($array as $key => $value) {
            $data[] = sprintf('%s => %s', $key, static::toString($value));
        }

        return sprintf('Array(%s)', implode(', ', $data));
    }
518453
static function build_line($array)
    {
        if (self::$data_sep)
        {
            $line = '';
            foreach ($array as $k => $v)
            {
                $line .= $k . self::$data_sep . $v . self::$col_sep;
            }
            return rtrim($line, self::$col_sep);
        }
        else
        {
            return implode(self::$col_sep, $array);
        }
    }
1225332
private static function image(string $url, string $image, bool $isUrl = false)
    {
        if ($isUrl) {
            $data = [
                'image_url' => $image,
            ];
        } else {
            $data = [
                'image' => self::encode($image),
            ];
        }

        return Request::exec($url, $data);
    }
765658
public static function post2https($fields_arr, $url)
    {
        $fields_string = '';
        //url-ify the data for the POST
        foreach ($fields_arr as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        $fields_string = substr($fields_string, 0, -1);

        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, count($fields_arr));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


        //execute post
        $res = curl_exec($ch);

        //close connection
        curl_close($ch);
        return $res;
    }
123075
public function reply(array $data = [], $return = false, $isEncrypt = false)
    {
        $xml = Tools::arr2xml(empty($data) ? $this->message : $data);
        if ($this->isEncrypt() || $isEncrypt) {
            if (!class_exists('Prpcrypt', false)) {
                require __DIR__ . '/Prpcrypt.php';
            }
            $prpcrypt = new \Prpcrypt($this->config->get('encodingaeskey'));
            // 如果是第三方平台，加密得使用 component_appid
            $component_appid = $this->config->get('component_appid');
            $appid = empty($component_appid) ? $this->appid : $component_appid;
            $array = $prpcrypt->encrypt($xml, $appid);
            if ($array[0] > 0) throw new InvalidDecryptException('Encrypt Error.', '0');
            list($timestamp, $encrypt) = [time(), $array[1]];
            $nonce = rand(77, 999) * rand(605, 888) * rand(11, 99);
            $tmpArr = [$this->config->get('token'), $timestamp, $nonce, $encrypt];
            sort($tmpArr, SORT_STRING);
            $signature = sha1(implode($tmpArr));
            $format = "<xml><Encrypt><![CDATA[%s]]></Encrypt><MsgSignature><![CDATA[%s]]></MsgSignature><TimeStamp>%s</TimeStamp><Nonce><![CDATA[%s]]></Nonce></xml>";
            $xml = sprintf($format, $encrypt, $signature, $timestamp, $nonce);
        }
        if ($return) return $xml;
        @ob_clean();
        echo $xml;
    }
42591
protected static function addTypedURL(&$array, $url, $type=null) {
		if( !$type ) {
			$type = self::LINK_TYPE_CUSTOM;
		}
		if( !isset($array[$type]) ) {
			$array[$type] = array();
		}
		$array[$type][] = $url;
	}
5134
public function filter(&$array) {
        while(list($key, $var) = each($array)) {
            if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || '' . intval($key) == "$key")) {
                if (is_string($var)) {
                    $array[$key] = stripslashes($var);
                }
                if (is_array($var))  {
                    $array[$key] = $this->filter($var);
                }
            }
        }
        return $array;
    }
620830
public function query($array)
	{
		$array['action'] = 'query';
		$array['format'] = 'php';

		$apiResult = $this->session->get($this->api.'?'.http_build_query($array));

		return unserialize($apiResult->body);
	}
22624
public function multiAttr(String $str, Array $array = []) : String
    {
        $perm  = $this->settings['attr']['perm'] ?? NULL;

        if( is_array($array) )
        {
            $open  = '';
            $close = '';
            $att   = '';
           

            foreach( $array as $k => $v )
            {
                if( ! is_numeric($k) )
                {
                    $element = $k;

                    if( ! is_array($v) )
                    {
                        $att = ' '.$v;
                    }
                    else
                    {
                        $att = $this->attributes($v);
                    }
                }
                else
                {
                    $element = $v;
                }

                $open .= '<'.$element.$att.'>';
                $close = '</'.$element.'>'.$close;
            }
        }
        else
        {
            return $this->_perm($perm, $str);
        }

        return $this->_perm($perm, $open.$str.$close);
    }
480732
private function fromArrayToString(array $fromArray): string
    {
        // $fromArray = [ 'john.doe@example.com' => 'John Doe', 'jane.doe@example.com' => 'Jane Doe' ]; // sample
        if (count($fromArray) > 0) {
            reset($fromArray);
            $fromString = key($fromArray);

            return $fromString;
        }

        throw new \InvalidArgumentException('Set at least one \'from\' address when using '.self::class);
    }
173056
protected function _processLinks(array &$array)
    {
        $base = $this->getUrl()->toString(KHttpUrl::AUTHORITY);

        foreach ($array as $key => &$value)
        {
            if (is_array($value)) {
                $this->_processLinks($value);
            }
            elseif ($key === 'href')
            {
                if (substr($value, 0, 4) !== 'http') {
                    $array[$key] = $base.$value;
                }
            }
            elseif (in_array($key, $this->_text_fields)) {
                $array[$key] = $this->_processText($value);
            }
        }
    }
909471
public static function decode(String $data, Bool $array = false)
    {
        if( $array === false )
        {
            return (object) unserialize($data);
        }
        else
        {
            return (array) unserialize($data);
        }
    }