I've been at this for a while now... My code in index.php
render ("portfolio.php", ["cash" => $_SESSION["cash"] ]
Then in portfolio.php
<?= $cash ?>
I get a error " Undefined index: cash" which is in portfolio... Help me please
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
Ok, so I will answer my own question.
What query does is make an array of arrays of sorts. So when you do:
<?php print_r($cash) ?>
You will get a output of all the 'things' in your array. The output says
( => Array([cash] => 10000.000))
notice how cash is nested in the 0th index of $cash. So to access this, you must first access array 0 of $cash by
Then you must access the cash in array 0 by adding this on
That fixes the problem, assuming your print_r outputs the actual value of cash.