aliov
aliov

Reputation: 97

Have problem changing a value in an array

I have a multi-dimensional array with 4 entries in each value - (1st name, last name, email, password). I am trying to format the password value so I can insert it into a database. As you can see, my results are not what I need. Why is this the result and what should I do to get my intended result? Thanks

php > $newlines[1][3] = "PASSWORD($newlines[1][3)]";  
php > echo $newlines[1][3];  
PASSWORD(Array[3)]

Upvotes: 0

Views: 120

Answers (3)

Felix Kling
Felix Kling

Reputation: 816262

You have a typo:

php > $newlines[1][3] = "PASSWORD($newlines[1][3)]";
                                                ^

But this not the only problem. You are accessing a multi-dimensional array and therefore, you have to put the array access into brackets {}. Otherwise, PHP would only subsitute the variable up to the first index (i.e. $newlines[1]). See also variable parsing.

And as $newlines[1][3] is most likely a string, you should also put quotation marks around it:

php > $newlines[1][3] = "PASSWORD('{$newlines[1][3]}')";

or even better in my opinion:

php > $newlines[1][3] = "PASSWORD('" . $newlines[1][3] . "')";

Upvotes: 4

JYelton
JYelton

Reputation: 36512

This appears to be a quotation mark placement problem. You want the result of the function Password() rather than the string "Password(-arguments-)".

Drop the quotations around the right side:

php > $newlines[1][3] = password($newlines[1][3]);

Upvotes: 1

baloo
baloo

Reputation: 7755

"PASSWORD($newlines[1][3)]"

Should be

"PASSWORD({$newlines[1][3]})"

Upvotes: 2

Related Questions