php - how to use variable content as a part of a other variable name?

Solution:

This would be far better implemented using arrays.

e.g.

<?php
$vidoos = array(
  "fk16zv6mw2jj", 
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs",
  "eztx3n90w8xs"
);

$titlenumber = 0;
$vidoo="https://vidoo.tv/e/";

echo $vidoo.$vidoos[$titlenumber];

$titlenumber = 3;
echo "<br/>"; //line break, just for demo
echo $vidoo.$vidoos[$titlenumber];
?>

Note that arrays start their indexes at 0 by default, so if you can start titlenumber at 0 too, you can do it simply like I've shown. If not, shift the array as shown in this answer

BTW you don't have to write a new <?php on every line. Just write it once at the start of the section of PHP, and close it once with ?> at the end. Lines in between only need to end with ;.

Answer

Solution:

You can use concatenation as the following example shows:

$iterator = 1;
$variableName = 'vidooid';

$vidooid1 = 'some value';

echo ${$variableName . $iterator}; // outputs 'some value'

As the others said before, you should learn how to use arrays with PHP. The above shown solution is okay, but should not be used when you can use arrays instead.

Source