Not a bug, but wondering if someone can explain why this works... I'm attempting to display someone's name and cash position.
In index, I query the tables for the relevant values. This returns an array of rows, as I've found out.
I'm then passing an element of the array to another view (portfolio). For example:
render("portfolio.php", ["title" => "Portfolio", "positions" => $positions, "cash" => $cash[0], "name" => $name[0]]);
However, when I go to portfolio.php and attempt to do something like this:
<h2>You have $<?=$cash ?> to spend</h2>
It throws up an invalid 'array to string conversion'.
OK so maybe it's put the cash in an array. Let's try:
<h2>You have $<?=$cash[0] ?> to spend</h2>
Nope. There you get an 'undefined offset' error.
OK, so maybe we need to call the the 'cash' value in the 'cash' array?
<h2>You have $<?=$cash['cash'] ?> to spend</h2>
It works!
The question is why? In C, if we index an array, it returns a value of type [int, string, whatever], not another array. Why isn't that the case in PHP?
Is it because the rows themselves are associative arrays, and so I can never actually extract a single value? If that's the case, how would I just pass one variable out of an associative array?