我有一個PHP腳本,看起來像這樣:的MongoDB - PHP - 插入爲數字
$contacts["{$firstname}"] = $_POST["{$firstname}"] ;
$contacts["{$lastname}"] = $_POST["{$lastname}"] ;
$contacts["{$age}"] = $_POST["{$age}"] ;
$collection->insert($contacts);
所以這個工作正常,但我所有的這些值都進入我的收藏爲「fistname」,「姓氏」和「年齡」都帶有引號。我想要名字和姓氏周圍的引號,但我希望年齡字段作爲數字/整數插入而不是引用的字符串。我如何確保年齡字段和其他數字字段作爲數字進入MongoDB /集合?
我在想像這樣:integer - > $ _POST [「{$ age}」]但我確定這是不正確的。再次使用PHP而不是shell。 Thnaks。
謝謝你的幫助。
你怎麼能確認的任何字符串'$ firstname'家店是$ _ POST可用?使用http://php.net/manual/en/function.isset.php來檢查。 –