I'm having a lot of trouble understanding these arrays in php. Here I want to query SQL to get me the value of cash of the user. Then I want to add it to the $position variable that is later sent to the view. I'v tried a lot now, but i get the error message: Notice: Undefined index: cash
// configuration
require("../includes/config.php");
$id = $_SESSION["id"];
$rows = query("SELECT * FROM `stocks` WHERE $id");
$cash = query("SELECT cash FROM `users` WHERE id = ?", $_SESSION["id"]);
print_r(array_values($cash));
print_r(array_values($rows));
$positions = [];
$positions[] = ["cash" => $cash["cash"]];
foreach ($rows as $row)
{
$stock = lookup($row["symbol"]);
if ($stock !== false)
{
$positions[] = [
"name" => $stock["name"],
"price" => $stock["price"],
"shares" => $row["shares"],
"symbol" => $row["symbol"],
];
}
}
render("portfolio.php", ["positions" => $positions, "title" => "Portfolio"]);