http_build_query

PHP 5, PHP 7, PHP 8
http_build_query - Generate URL-encoded query string

Example #1 Simple usage of http_build_query

Result: foo=bar&baz=boom&cow=milk&php=hypertext+processor foo=bar&baz=boom&cow=milk&php=hypertext+processor
PHP Version:

Example #2 http_build_query with numerically index elements.

Result: 0=foo&1=bar&2=baz&4=boom&cow=milk&php=hypertext+processor myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_4=boom&cow=milk&php=hypertext+processor
PHP Version:

Example #3 http_build_query with complex arrays

Result: user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M& user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&pastimes%5B1%5D=opera& pastimes%5B2%5D=poker&pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12& children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8& children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO
PHP Version:

Example #4 Using http_build_query with an object

Result: pub=publicParent&pub_bar%5Bpub%5D=publicChild
PHP Version:


Example #5 of http_build_query

PHP Version:


Function http_build_query:

URLs Functions

Most used PHP functions