WordPress Merged Array with Default Args

<?php // FROM ARRAY $args = array ( 'foo' => 'baz' ); $defaults = array ( 'foo' => 'bar', 'hello' => 'world' ); $merged = wp_parse_args( $args, $defaults ); /* Array ( [foo] => baz [hello] => world ) */ // FROM URL ARGS $url = 'http://example.com/?x=y&hello=moon'; list($url, $args) = explode ( '?', $url); $defaults = array ( 'foo' => 'bar', 'hello' => 'world' ); $merged = wp_parse_args( $args, $defaults ); /* Array ( [foo] => bar [hello] => moon [x] => y ) */

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.