I am working on quote.php. I am trying to get a template to display the value of a stock by taking the associative array from


and passing it to render, but I'm not quite sure how. According to its declaration render takes


I'm not sure how to pass an array with three parts to render. I've tried several tactics (after also including the name of the template that I'm trying to render--that part works).

render("template.php", $stock);  // Seemed like this should have worked but I got an undefined variable error.
render("template.php", "$stock"=>"price"); 

I tried a few other formats, just guessing to see if one would work, because I'm not sure why $stock didn't work. Sorry if it's something obvious.

  • I've not actually done this pset yet, but you can declare and populate an associative array like this: $array = Array('key1'=>'value','key2'=>'value2','key3'=>'value3'); Jun 17, 2014 at 3:47

2 Answers 2


It should be:

render("template", ["price" => $stock["price"]]);

And if you want to pass the entire array then:

render("template", ["any_variable" => $stock]);

Take a look at "$stock"=>"price" in your code, the first argument should be the key not a variable name, and the second should be the variable name, you have them the wrong way around, which is why you are getting an error is saying $stock is undefined. Compare it to the way the apologize function sends the message to be displayed via the apology.php template.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .