简体   繁体   中英

How to echo php variable from array?

I need echo something like this:

echo "<a href="#">$some['variable']</a>

How can I escape [] brackets to echo variable in link?

echo "<a href='#'>" . $some['variable'] . "</a>";

or

echo "<a href=\"#\">" . $some['variable'] . "</a>";

or

echo "<a href='#'>{$some['variable']}</a>";

尝试这种方式:

echo "<a href='#'>{$some['variable']}</a>";
  • My favorite:

     echo "<a href='#'>$some[variable]</a>"; 
  • The only one that should ever be used

     <a href="#"><?=$some['variable']?></a> 

    or (preferred)

     <a href="#">{{ some.variable }}</a> 

A note for the fellow experts: If you think that some of these codes are improper, consult documentation first.

有2种好的方法:

  1. echo '<a href="#">'.$some['variable'].'</a>';
  2. echo "<a href=\\"#\\">$some['variable']</a>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM