waiwai933
waiwai933

Reputation: 14559

How to access an array element by its key which is wrapped in single quotes?

I'm having a problem with arrays:

print_r($_POST['bank']);

produces Array ( ['deposit'] => 30 )

However,

assert($_POST['bank']['deposit'] == 30);

which immediately follows print_r, fails. Since nothing is changing the value of $_POST, I suppose my syntax is wrong, but I can't see it for the life of me.

Upvotes: 1

Views: 93

Answers (1)

waiwai933
waiwai933

Reputation: 14559

Ugh, I just realized it.

assert($_POST['bank']['\'deposit\'']==30);

works fine, because "deposit" had had extra single quotes around it.

Upvotes: 2

Related Questions