2015-10-01 60 views
-2

爲什麼在我保存序列化數據後,它給了我一個布爾輸出,我的輸入結果是b:1?下面是已經保存在我的數據庫中的數據。以序列化的形式顯示布爾整數php

a:2:{s:30:"features_safety_number_airbags";b:1;s:29:"features_safety_trans_control";b:1;} 

這是插入代碼。

if(isset($_POST['submit'])){ 

     $add_item_features = array(
      "features_safety_number_airbags" => isset($_POST['safety_airbags']), 
      "features_safety_trans_control" => isset($_POST['safety_traction']), 
      ); 

     $add_item_features_serialize = serialize($add_item_features); 

     $sql = "INSERT INTO item_newcar_temp(`item_features`) VALUES ('".$add_item_features_serialize."')"; 
+0

我嘗試使用strpilashes..not工作對我..我只是一個初學者.. – dextree

回答

0

這是由於這樣的事實,你的陣列值實際上設置爲isset()功能,這是一個布爾值的回報。

var_dump(isset($a)); // will return boolean(true/false) 

你想要的是一個Ternary Operator,那應該是這樣的:

$add_item_features = array(
    "features_safety_number_airbags" => ((isset($_POST['safety_airbags'])) ? $_POST['safety_airbags'] : 'it wasnt set..'), 
    "features_safety_trans_control" => ((isset($_POST['safety_traction'])) ? $_POST['safety_traction'] : 'it wasnt set..'), 
); 

將返回看起來類似於序列化項目:

a:2:{s:30:"features_safety_number_airbags";s:14:"it wasnt set..";s:29:"features_safety_trans_control";s:14:"it wasnt set..";} 

Demo/Example

+0

比k你先生..這節省我的時間...但是他們給我一個減去這個..我不知道是什麼原因... – dextree