title: Echo JavaScript alert of a PHP array value on an HTML button?
body: <p>I'm trying to use PHP to echo a set of buttons (buy &amp; sell) in a stock trading game. The buttons will eventually have an onclick= event handler that calls a JavaScript function to populate some fields on a form, but I'm just trying to get an alert() with one piece of data to work. I just can't get the results from my echo statement to print the alert correctly, so it doesn't even trigger. I've also used print_r ($stockInfo) to ensure my array is properly filled with test data.</p>
  
  <p>Here's my array:</p>
  
  <pre><code>$stockInfo = array(
      array('name' =&gt; 'Company 1', 'description' =&gt; 'Description 1', 'price' =&gt; '100', 'yield' =&gt; '.05'),
      array('name' =&gt; 'Company 2', 'description' =&gt; 'Description 2', 'price' =&gt; '89', 'yield' =&gt; '.06'),
      array('name' =&gt; 'Company 3', 'description' =&gt; 'Description 3', 'price' =&gt; '110', 'yield' =&gt; '.03')
  );
  </code></pre>
  
  <p>And my PHP code that attempts to generate a button:</p>
  
  <pre><code>&lt;?php
  echo &lt;&lt;&lt;EOT
      &lt;button id="buy" class="btn btn-primary btn-small" onclick="alert('$stockInfo[0]["name"]');"&gt;Buy&lt;/button&gt;
  EOT;
  ?&gt;
  </code></pre>
  
  <p>The result of that code is:</p>
  
  <pre><code>&lt;button id="buy" class="btn btn-primary btn-small" onclick="alert('Array["name"]');"&gt;Buy&lt;/button&gt;
  </code></pre>
  
  <p>I just can't figure out why I can't get even a simple alert to fire. Running:</p>
  
  <pre><code>echo $stockInfo[0]["name"];
  </code></pre>
  
  <p>Correctly prints out "Company 1", but it doesn't print that text in the argument of the alert().</p>
  
  <p>I've read Stackoverflow, lots of web articles, and experimented for the past day and I just can't figure this out. If anyone can provide any help, I'd GREATLY appreciate it.</p>
  
  <p>Thanks!</p>