1
I’m trying, inside a classe
, create a property that will be populated by an array.
The problem is that the second index of this array depends on the value of the first one and would like to concatenate.
private $site = array (
"dominio" => "site.com.br",
"www" => "www.".->dominio,
How to do this?
Like the
$site
is being populated? Through a set?– Costamilam
no! Via the array itself. I edited the question.
– Carlos Rocha
How about
$site = ["dominio" => "site.com.br"]; $site["www"] = "www." . $site["dominio"];
? You can also use the functionend($site)
to return the last element of the array, just be careful that the internal pointer will be modified.– Caio
"www" => $site["domain"],, did not roll;
– Carlos Rocha
even because the variable (array) $site is not yet complete on this line!
– Carlos Rocha
Something like this, https://ideone.com/TaNLrQ?
– Woss