Saltern
Saltern

Reputation: 1383

php : how to join 2 varibale and use that for one variable?

$x = 1;


if (isset($locats))
    {
    foreach ($locats as $l)
        {
        ${"variable$x"} = new LatLng(['lat' => $l['google_map_lat'], 'lng' => $l['google_map_lng']]);

        ${"marker$x"} = new Marker([
            'position' =>$variable."$x"  ,
            'title' => $l['name'],
        ]);



        $x++;
        }
    }

i want join 2 varibale and use that in one variable!

in :

 'position' =>$variable."$x"  ,

i want set $variable1 and in next time $variable2 and .... for position

Upvotes: 1

Views: 22

Answers (1)

Rajdeep Paul
Rajdeep Paul

Reputation: 16963

Use variable variables, like this:

$variable = "variable" . $x;

And use it like this:

$$variable // would give $variable1, $variable2 etc.

Upvotes: 1

Related Questions