user3527279
user3527279

Reputation: 23

Php access variable

In PHP i have array variable from another function like this $v->params:

(
    [{"username":"myusername","email":"myemail@gmail_com","phone":"0123456789","password":"abc123","fullname":"myfullname","register_ip":"127_0_0_1","country":"Qu\u1ed1c_Gia","birthday":"N\u0103m_sinh","gender":"male","bank_code":"Ng\u00e2n_h\u00e0ng","ip":"127_0_0_1","os":"Windows_10","device":"Computer","browser":"Mozilla_Firefox_77_0"}] => 
)

Now i want to access to it item, how can i code to access item value like this:

$password = $v->params->password; //myemail@gmail_com

I new with PHP thank you all

Upvotes: 1

Views: 42

Answers (1)

Nigel Ren
Nigel Ren

Reputation: 57121

The data seems the wrong way round as it's the key of the array rather than a value.

So using array_keys()[0] to get the first key and then json_decode this...

$data = json_decode(array_keys($v->params)[0]);

you can then use the $data object to get at the values...

echo $data->username;

Upvotes: 1

Related Questions