Creating Variable in PHP from Database Entries

I have an array that is stored in the WordPress options database. I want to pull the data from the array and create a new variable that has the same name and value as what is stored in the database. I can pull the array values, but I am having dificulties creating a variable with the name of the value in the database. I can create a variable manually, but since the variable will changed based on each user I need to names to be assigned.

I have an array named $variables with the values below

Read More
Brandon => Swansone
David => Thompson
Wayne => Handy

I can call the values and assign them to a variable

foreach ($variables as $k => $v) {
      $k = $v;
}

I was hoping it would create a new variable with the name of what $k is and assign the value of $v to it. Instead if just assigns the value of $v to the variable $k instead of creating a new variable. So I want the end result to be

$Brandon = 'Swansone';
$David = 'Thompson';
$Wayne = 'Handy';

Any ideas?

Related posts

2 comments

  1. I think you should see this page.

    The extract() method is your friend.

    Other solution is a loop and double $ sign as variables variable. But why would you like to write a loop if there is a method?

Comments are closed.