filmesson
filmesson

Reputation: 21

how to get a third variable using a doubled join variable in php

PHP CODE:

$video1="welcome.mp4";
$video2="movie.mp4";
$video3="ends.mp4";

$num_id="1";
$get = '$' . "video" . $num_id; 
$file = $get;
echo "<a href=Player.php?file=$file'>Play</a>";

html code results:

<a href="player.php?file=$video1">Play</a>

HTML - expectancy:

<a href="player.php?file=welcome.mp4">Play</a>

Upvotes: 0

Views: 32

Answers (2)

ArtisticPhoenix
ArtisticPhoenix

Reputation: 21681

I would do this (If I wanted to be Kool, or confuse a junior developer .. lol )

$video1="welcome.mp4";
$video2="movie.mp4";
$video3="ends.mp4";

$num_id="1";
$get = ${"video".$num_id}; 
$file = $get;
echo "<a href=Player.php?file=$file'>Play</a>";

Output

<a href=Player.php?file=welcome.mp4'>Play</a>

But I am not sure you are ready to have access to that much power...

Sandbox

Upvotes: 0

Jason K
Jason K

Reputation: 1381

I would do something like this.

$videos = ['welcome.mp4','movie.mp4','ends.mp4'];

foreach($videos as $video){
  echo "<a href=Player.php?file=$video'>Play</a><br>";
}

Upvotes: 1

Related Questions