2

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.

2
  • What exactly are you asking? Your code appears to be correct. Commented Aug 19, 2010 at 14:39
  • sorry, i left a sentence out of the question. Commented Aug 19, 2010 at 14:42

2 Answers 2

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

But you're better off using arrays:

$sidecount = array("F" = array(), "B" => array());
$sidecount[$side][$plate] = /* ... */
Sign up to request clarification or add additional context in comments.

1 Comment

Agreed with array using! Gives much more flexibility in the end... At least it always happens with my scripts.
0
$_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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.