开发者

PHP using a variable in a variable name

I have two preexisting variables:

$side (which is either F or B)

and

$plate (which is a 3 digit number)

I am trying to build two arrays called

$sidecountF

and $sidecountB

using the following code:

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

assuming $side开发者_运维百科 is F and $plate is 200, I'm hoping that the end result is that

$sidecountF[200] = 1;

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

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

So now I'm stumped.


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

But you're better off using arrays:

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


$_blank = array(
    'sidecount' . $side => array()
);

extract($_blank);

this would be another way of doing it, it also is not bound to creating 1 variable with ${""} you can create several variables at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜