PHP连接两个变量名 [英] PHP join two variable names

查看:385
本文介绍了PHP连接两个变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,该脚本获取$_POST来决定要返回哪个数组.例如:

I have a php script that gets a $_POST to decide which array to return. Ex:

$n = $_POST['n']; // 1, 2 or 3

$a1 = array ('something', 'something else', 'another thing');

$a2 = array ('something 2', 'something else 2', 'another thing 2');

$a3 = array ('something 3', 'something else 3', 'another thing 3');

现在我想获取与$n值相对应的数组,比方说"2".

now I want to get the array that corresponds to the $n value, let's say "2".

我怎么说echo $a . $n来获得$a2

谢谢.

推荐答案

${'a'.$n}如果$n2,则为您提供$a2.

${'a'.$n} gives you $a2 if $n is 2.

这篇关于PHP连接两个变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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