在PHP中将多个变量分配给单个变量 [英] Assigning multiple variables to a single in PHP

查看:80
本文介绍了在PHP中将多个变量分配给单个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是从保存在variables.php文件中的一个变量中调用我的所有元标记.

我可以单独回显它们,但是我想为它们分配相同的名称,因此网页中的回显脚本较小.我知道这是您将相同的值分配给整数的方式,但是我找不到用字符串值做到这一点的解决方案(我认为它们是正确的字符串吗?)

$john = $ jane = 3;

我在尝试什么.

$metaAuthor = $metaDescription = $metaImage = $metaTitle =$meta;

当您不使用数字时,我认为它是一个不同的命令吗?

解决方案

每种数据类型,字符串,整数,数组等的工作方式都相同.

这里有一个小演示:

http://sandbox.onlinephpfunctions.com/code/325104e0194b11b98fd7df58953aec4b0pb1468>

在您发表评论之后,您可能想要这样做:

$meta = $metaAuthor." ".$metaDescription." ".$metaImage ." ".$metaTitle;

数组的工作方式如下:

$meta = array("author" => $metaAuthor, "description" => $metaDescription );
echo $meta['author']; 

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?)

$john = $ jane = 3;

What I am trying.

$metaAuthor = $metaDescription = $metaImage = $metaTitle =$meta;

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:

$meta = $metaAuthor." ".$metaDescription." ".$metaImage ." ".$metaTitle;

An array works like this:

$meta = array("author" => $metaAuthor, "description" => $metaDescription );
echo $meta['author']; 

这篇关于在PHP中将多个变量分配给单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆