user1636452
user1636452

Reputation: 3

PHP Arrays, referencing an earlier value in same array

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!

Upvotes: 0

Views: 44

Answers (1)

Jason McCreary
Jason McCreary

Reputation: 72961

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';

Upvotes: 4

Related Questions