在PHP中将多个变量分配给单个变量 [英] Assigning multiple variables to a single in PHP
问题描述
我想做的是从保存在variables.php文件中的一个变量中调用我的所有元标记.
我可以单独回显它们,但是我想为它们分配相同的名称,因此网页中的回显脚本较小.我知道这是您将相同的值分配给整数的方式,但是我找不到用字符串值做到这一点的解决方案(我认为它们是正确的字符串吗?)
$john = $ jane = 3;
我在尝试什么.
$metaAuthor = $metaDescription = $metaImage = $metaTitle =$meta;
当您不使用数字时,我认为它是一个不同的命令吗?
每种数据类型,字符串,整数,数组等的工作方式都相同.
这里有一个小演示:
http://sandbox.onlinephpfunctions.com/code/325104e0194b11b98fd7df58953aec4b0pb1468>
在您发表评论之后,您可能想要这样做: 数组的工作方式如下: What I want to do is call all of my meta tags from one variable kept in the variables.php file. I can echo them individually but I want to assign them all the same name so the echo script in the webpage is smaller. I understand that this is how you assign the same value to an integer but I cannot find the solution to do this with string values(I think they are string right?) What I am trying. I assume its a different command when you are not using numbers? It is the same for every datatype, strings, ints, arrays, etc work all the same. A little demo here: http://sandbox.onlinephpfunctions.com/code/325104e0194b11b98fd7df58953aec4b0deb1468 Af of your comment you probably want this: An array works like this:
这篇关于在PHP中将多个变量分配给单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!$meta = $metaAuthor." ".$metaDescription." ".$metaImage ." ".$metaTitle;
$meta = array("author" => $metaAuthor, "description" => $metaDescription );
echo $meta['author'];
$john = $ jane = 3;
$metaAuthor = $metaDescription = $metaImage = $metaTitle =$meta;
$meta = $metaAuthor." ".$metaDescription." ".$metaImage ." ".$metaTitle;
$meta = array("author" => $metaAuthor, "description" => $metaDescription );
echo $meta['author'];