函数返回Assoc数组


Function Return Assoc Array

所以我有下面的函数,但由于某种原因,当我在页面中使用它时,它不会返回assoc数组。如果我在函数内部的数组上打印_r,它会打印出数组,但当我在页面上调用函数/数组时,它不起作用。它是空白的。不确定我做错了什么。

function fetch_one($Table, $PK) {
    include ("pdo_connection.php");
    $sql = 'SELECT * FROM `'.$Table.'` WHERE PK = ? LIMIT 1';
    //echo $sql;
    $stmt = $db->prepare($sql);
    $PK = (int)$PK;
    $stmt->bindParam(1, $PK);
    $stmt->execute();
    $View = $stmt->fetch(PDO::FETCH_ASSOC);
    return $View;   
}

在页面上我有

fetch_one($table, $pk);
print_r($View)

它什么也不回。

当你运行它时,你必须将值分配给一个变量,否则就使用它

$x = fetch_one($table, $pk);
print_r($x);

print_r(fetch_one($table, $pk));