John Smith
John Smith

Reputation: 117

two variables values in one variable is possible?

My code:

$url = "http://www.google.com/test";

$parseurl = parse_url($url);

$explode = explode('.', $parseurl['host']);

$arrayreverse = array_reverse($explode);

foreach(array_values($arrayreverse) as $keyvalue) {
    $result[] = $keyvalue;
}

$implode = implode('.', $result);
...

I'm interested to have values in one variable from $implode result and the result if isset the path from $parseurl... how can I do that ?

EDIT:

I want the values of $implode + and(if isset $parseurl['path']); to be in 1 variable but I can't figure out how to unite them.

Upvotes: 0

Views: 79

Answers (1)

Barmar
Barmar

Reputation: 782295

Is ths what you want?

$newurl = $implode . (isset($parseurl['path']) ? $parseurl['path'] : '');

It uses the conditional operator to return either the path or an empty string, and concatenate that onto $implode.

Upvotes: 3

Related Questions