0

Hi I'm trying to do this

$system = array(
'key1'  => 'val1',
'key2'  => 'val2',
'key3'  => $system['key1'].'val3'
);

But when we echo key3 it ends up as just "val3" rather than "val1val3".

Is there a way around this problem?

Thanks!

3
  • $system is not an array at the moment you ask for index key1. The parameters are processed before the assignment operator here. Commented Jul 24, 2013 at 15:34
  • 1
    @Virus721 it might be an array, it might be some other type, it might be non-existent .. we can't say from the given snippet ... ;-) Commented Jul 24, 2013 at 15:35
  • $system is not an array - or has not index key1 - at the moment you ask for index key1 Commented Jul 24, 2013 at 15:43

1 Answer 1

4

Is there a way around this problem?

You can assign it after you declare $system/key1:

$system = array('key1' => 'val1', 'key2' => 'val2');
$system['key3'] = $system['key1'] . 'val3';
Sign up to request clarification or add additional context in comments.

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.