PHP 在变量名中使用变量 [英] PHP using a variable in a variable name

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

问题描述

我有两个预先存在的变量:

I have two preexisting variables:

$side(F 或 B)

$plate(这是一个 3 位数字)

$side (which is either F or B)
and
$plate (which is a 3 digit number)

我正在尝试构建两个名为

I am trying to build two arrays called

$sidecountF
$sidecountB

使用以下代码:

$sidecount{$side}[$plate] = 1;

假设 $side 是 F 并且 $plate 是 200,我希望最终结果是

assuming $side is F and $plate is 200, I'm hoping that the end result is that

$sidecountF[200] = 1;

我在开始时将 sidecountFsidecountB 声明为带有

I am, at the beginning, declaring sidecountF and sidecountB as arrays with

$sidecountF = array();
$sidecountB = array();

所以现在我很难过.

推荐答案

${"sidecount$side"} = array();

但最好使用数组:

$sidecount = array("F" = array(), "B" => array());
$sidecount[$side][$plate] = /* ... */

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

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