如何在php中更改提供数组的指定数量

My code is given bellow

Controller code:

class statController extends baseController {

public function index() {
    $this->registry->template->projectsWise = $this->selectProjectWise();
    $this->registry->template->show("stat");
}

private static function selectStat($query, $values) {

    $statMapper = new statMapper();
    $select = new common();
    $select->setItems($query);
    $select->setValues($values);
    return $statMapper->select($select);
}

private function selectProjectWise() {
    $date = date("Y-m-d");
    $values = array($date, $date);
    return self::selectStat("project_wise", $values);
}
private function selectLocationWise(){
    $date = date("Y-m-d");
    $values = array($date, $date, 1);
    return self::selectStat("location_wise", $values);
}

Mapper code:

class statMapper extends baseMapper {

private $query = array(
    "project_wise" => "SELECT p.proj_Name, p.proj_Type, p.proj_Category, COUNT(ra.emp_Id) as allocation FROM project AS p, resource_assignment AS ra WHERE p.proj_Start_Date <= '%s' AND p.proj_End_Date >= '%s' AND p.proj_Status = 1 AND ra.proj_Id = p.proj_Id GROUP BY p.proj_Name ",
    "location_wise" => "SELECT e.user_Location, p.proj_Name, p.proj_Type, p.proj_Category, COUNT(ra.emp_Id) as allocation FROM project AS p, resource_assignment AS ra, employee as e WHERE p.proj_Start_Date <= '%s' AND p.proj_End_Date >= '%s' AND p.proj_Status = %d AND ra.proj_Id = p.proj_Id GROUP BY p.proj_Name "
);

public function select($select) {
    $connect = parent::connect();
    $query = sprintf($this->query[$select->getItems()], $select->getValues()[0], $select->getValues()[1]);
    try {
        $result = $connect->query($query);
        if ($result) {
            $table = array();
            while ($row = $result->fetch_object()) {
                $table[] = $row;
            }
            return $table;
            parent::disconnect();
        } else {
            throw (new Exception($connect->error . "<br/>" . $query . "<br/>"));
        }
    } catch (Exception $exp) {
        require_once 'views/error.php';
        exit();
    }
}

}

I have added 3 specifiers ($query->"location_wise") In statController->selectLocationWise() function. When I use it how do I add $select->getValues()[2] value in statMapper->select(), instead of add it manually.

You can use http://www.php.net/manual/ru/function.vsprintf.php instead of sprintf to pass whole array as argument.

But anyway your code looks bad. From the outside view of StatMapper there is no way to identify neither types of arguments, nor their count. Code will be hard to be maintained.

I advise to use Data Access Objects pattern or learn framework.