示例#1
0
/**
 * Generate a query string from an array, optionally replacing and/or removing
 * elements from the array (referenced by path).
 *
 * @param $array array to turn into a query string
 * @param $replace map of paths to replace, and their new values
 * @param $remvoe array of paths to remove
 */
function query_string(array $array, $replace = null, $remove = null)
{
    if ($replace !== null) {
        foreach ((array) $replace as $path => $v) {
            array_path_replace($array, $path, $v);
        }
    }
    if ($remove !== null) {
        foreach ((array) $remove as $path) {
            array_path_unset($array, $path);
        }
    }
    return array_url_encode($array);
}
示例#2
0
 function test_array_path_replace_with_non_existant_component()
 {
     array_path_replace($this->foo, 'bleem.blom.blam', 'HELLO THAR');
     assert_equal(array('bar' => 5, 'baz' => array('a' => 10, 'b' => 20, 'c' => array('d' => 'moose', 'e' => 'cow')), 'bleem' => array('blom' => array('blam' => 'HELLO THAR'))), $this->foo);
 }