0

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)]
2
  • 1
    It looks like the ) and ] are transposed, but I'm still not sure what you are going for here. is "PASSWORD" a function? Commented May 24, 2010 at 19:54
  • PASSWORD is a MySQL function I believe. Commented May 24, 2010 at 22:15

3 Answers 3

4

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] . "')";
Sign up to request clarification or add additional context in comments.

3 Comments

Your third suggestion using concatenation did the trick. All of the others returned Array[3] when I wanted the string that was in the Array. Thank you.
@aliov: The problem was, that if you don't put {} around the variable, PHP will only parse the variable up to the first index (i.e. $newlines[1]) which is an array and therefore prints Array. You are right, even if you had no typo, you would have got the wrong result. Putting it into brackets should work, but personally I find concatenation much more readable anyway (it is easier to see, what is PHP and what not).
Thanks for the mini-lesson and the sound advice. Much appreciated.
2
"PASSWORD($newlines[1][3)]"

Should be

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

Comments

1

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]);

2 Comments

PASSWORD() is probably the MySQL function.
Ah, then in that case, the other answers should suffice as the transposition of bracket and parenthesis looks suspect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.