php替换url参数实现商品筛选效果

<?php

/**
 * 替换地址参数
 * @param array $param
 */
function replaceParam($param) {
    $get = $_GET;
    if (!empty($param)) {
        foreach ($param as $key => $val) {
            $get[$key] = $val;
        }
        $url = array();
        foreach ($get as $key => $val) {
            $url[] = $key . '=' . $val;
        }
        return implode('&', $url);
    }
}

?>

<a href="ceshi.php?<?php echo replaceParam(array('city' => 0)) ?>">全部</a>
<a href="ceshi.php?<?php echo replaceParam(array('city' => 1)) ?>">广州</a>
<a href="ceshi.php?<?php echo replaceParam(array('cat_id' => 1)) ?>">分类1</a>
<a href="ceshi.php?<?php echo replaceParam(array('cat_id' => 2)) ?>">分类2</a>
原文地址:https://www.cnblogs.com/chenjiacheng/p/6522551.html