wp_parse_str()WP 2.2.1

Parses a string into variables to be stored in an array.

Used By: wp_parse_args()
1 time — 0.000001 sec (speed of light) | 50000 times — 0.07 sec (speed of light) | PHP 7.3.12, WP 5.3.2
Hooks from the function

Return

null. Nothing.

Usage

wp_parse_str( $string, $array );
$string(string) (required)
The string to be parsed.
$array(array) (required) (passed by reference — &)
Variables will be stored in this array.

Examples

0

#1 Demo

Let's break down the query string into array of key => value pairs:

$string = '?one=1&foo=some&two=2&bool=true';

wp_parse_str( $string, $array );

print_r( $array );

/* Will withdraw:

Array
(
	[?one] => 1
	[foo] => some
	[two] => 2
	[bool] => true
)
*/

Changelog

Since 2.2.1 Introduced.

Code of wp_parse_str() WP 6.0

function wp_parse_str( $string, &$array ) {
	parse_str( (string) $string, $array );

	/**
	 * Filters the array of variables derived from a parsed string.
	 *
	 * @since 2.2.1
	 *
	 * @param array $array The array populated with variables.
	 */
	$array = apply_filters( 'wp_parse_str', $array );
}