2

What is the deference between array('hi'=>$hello) and array(':hi'=>$hello)

I am using the second form to insert my data using prepare statement by extending PDO which is working fine. However when I change array declaration to first form array('hi'=>$hello) no data is being inserted, I was wondering how they both work.

1

2 Answers 2

1

':hi' is a named variable and also an index/key in your array this can pass values to your database (Used in PDO).

'hi' is just an index/key in your array

Sign up to request clarification or add additional context in comments.

Comments

0

Your first example:

array('hi' => $hello);

creates a key called 'hi', and your second example creates a key :hi. To use PDO parameters you need to prepend the parameters with a colon. The colon is used to designate and identify the parameters. See PDO prepared statement - what are colons in parameter names used for?

Comments

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.