Home  >  Article  >  Backend Development  >  How to convert array to url string in php

How to convert array to url string in php

王林
王林Original
2021-10-22 17:56:182298browse

php method to convert array to url string: [$queryStr = http_build_query($data);echo query_str;].

How to convert array to url string in php

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

First give an array:

$data = array('name' => 'tom', 'sex' => 1, 'channel' => 'ty');

Convert array to url parameter string

$queryStr = http_build_query($data);
echo query_str;

Execution result:

name=tom&sex=1&channel=ty

Convert url parameter string to array

parse_str($query_str,$query_arr);
print_r($query_arr);

Execution results:

array(name => tom,sex => 1,channel => ty)

Recommended learning:php training

The above is the detailed content of How to convert array to url string in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn