Can you turn a literal string into a variable?

Asked

Viewed 33 times

0

I searched the web, but I didn’t see how to turn a simple string into a variable, I saw parse_str but it’s not quite what I need. I want the following, I have the string "userName 1", and I would like it to be transformed into "$userName 1".

Suppose I have a Row["field name"] and it goes through a

foreach ($Row as $key => $value), 
quero transformar os nomes dos campos em variaveis, 
ou seja $."key" = $novovalor 

But he won’t take it. I need this because the strings come from a foreach and I don’t know exactly the content, I just know that it is not a content that can give error in the construction of the variable, because they are field names.

  • Why don’t you do : $nomeusuario1 = "sua string"; ?

  • 1

    There is, but usually you don’t have to do this, in virtually every case it is gambiarra, insecure and the programmer will get hurt with it. And I think it’s been answered before. I need to find.

  • Because user1 is an example, it does not exist, variables will be created from strings I do not know what are.

  • Depending on the answers I will analyze if it is feasible to use the suggestion or go to something else

  • Well if you detail a little more the way you receive this data... it gets better

  • @Magichat, suppose I have a Row["fieldname"] and it goes through a foreach ($Row as $key => $value), I want to transform the field names into variables, namely $."key" = $novovalor

  • Put that code there,,,

  • This is a case to use array even associative, as is spoken in the duplicate.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.