doudou8783 2016-03-08 22:33
浏览 20

PHP变量变量名

I need to use dynamic variable names to create an article template:

 $templatesAr = array("intro","paragraphs","image","conclusion","h2");
 $intro = "Intro";
 $paragraphs = "Paragraphs";
 $image = "image.png";
 $conclusion = "Conclusion";
 $h2 = "Heading";

$articletemplateAr = array("h2", "intro", "image",
    "h2", "paragraphs", "h2", "conclusion");`

How to echo $article in order from $articletemplateAr:

$article = $h2 . $intro . $image . $h2 . $paragraphs . $h2 . $conclusion;
  • 写回答

2条回答 默认 最新

  • duanluanhui8348 2016-03-08 22:37
    关注

    Use this code:

    $article = '';
    foreach($articletemplateAr as $item) {
        $article .= $$item;
    }
    
    评论

报告相同问题?