-1

I make a php file it named as baca.php like this :

<?php
$id=$_GET['id'];
$admin$id="anything";
?>

I want to make new variable with ID parameter value like
ex:
if ID parameter value is 1 so the variable is
$admin1="";
if ID parameter value is 2 so the variable is
$admin2="";


Help me please ^_^

  • 2
    Possible duplicate of [Using braces with dynamic variable names in PHP](https://stackoverflow.com/questions/9257505/using-braces-with-dynamic-variable-names-in-php) – Ethan Nov 17 '18 at 02:14
  • `${"admin$id"}="anything";` – Nick Nov 17 '18 at 03:32

1 Answers1

0

this is for limited variable:

<?php
$id=$_GET['id'];
if($id==='1'){
$admin1="anything";
}elseif($id==='2'){
$admin2="anything";
}//you can add more here
?>

i recommend:

<?php
$id=$_GET['id']-1;
$admins=array('admin1','admin2','admin3');//edit this array to add more
$the_admin=$admins[$id];//now this your admin with single variable
?>
Mahfuzar Rahman
  • 303
  • 3
  • 11