Ok, I'm at pset7 (C$50 Finance), more specifically trying to implement sell.php. I have created a template, sell_form.php, where users can select the symbol of the stock they want to sell and submitted. This symbol is posted to the controller sell.php, and it can be accessed at $_POST["symbol"]. Now what I want to do is to create a variable called $price where i can store the price of the given stock. I want to access the price that is present in the array "positions":
$positions = [];
foreach ($rows as $row)
{
$stock = lookup($row["symbol"]);
if ($stock !== false)
{
$positions[] = [
"name" => $stock["name"],
"price" => $stock["price"],
"shares" => $row["shares"],
"symbol" => $row["symbol"]
];
}
}
is there a way to access only the price of the symbol? If I do the following:
$price = positions[]["price"];
I'm pretty sure I'll get the prices of all the stocks owned by the user. In R accessing data it's pretty easy. All I would have to do is something like
price = positions$price[, symbol == "StockForSale"]
(Actually I'm a little bit rusty with R, so it's possible there is some syntax error, but you get the idea) Is there anything similar in php?