I have a php script that looks like this:
$contacts["{$firstname}"] = $_POST["{$firstname}"] ;
$contacts["{$lastname}"] = $_POST["{$lastname}"] ;
$contacts["{$age}"] = $_POST["{$age}"] ;
$collection->insert($contacts);
so this works fine but i all of these values are going into my collection as “fistname”, “lastname” and “age” with quotes around all. I want the quotes around first name and last name but i want the age field to insert as a number/integer not a quoted string. How do I make sure that the age field and other numeric fields go into the mongodb/collection as a number?
I was thinking something like: integer -> $_POST[“{$age}”] but im sure that’s not right. Again im using PHP not the shell. Thnaks.
Thank you for your help.
First, you don’t need all those quotes and braces. Second, try casting the value to an
intI’m assuming here that all the
$_POSTvars have been checked and validated and$firstname,$lastnameand$ageare all valid array key strings