rsabir rsabir - 1 year ago 71
PHP Question

Reference in element of the array another element of the same array

Is there a possibility to reference an element of an array in another element with the same array?

Let's say we want to make an array like this:

$a = array(
'base_url' => '',
'URL_SLO_OpenAM_OIC' => ''.$this['base_url'],

Of course, it doesn't work because $this is intended for classes not for arrays. So is there an alternative?

Answer Source

No it's not possible that way. You can't reference to the same array within its context. But here is a work around:

$a = array(
    'base_url' => ($base_url = ''),
    'URL_SLO_OpenAM_OIC' => ''.$base_url,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download