简体   繁体   English

如何从数组中回显PHP变量?

[英]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>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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