1 # CI cookie because it cannot store arrays, all must be serialized and stored in the array 2 3 # define Array 4 $ cookie_array = array (5 'shop _ id' => $ GID, 6 'shop _ name' => $ shop_obj [0] ['main _ title'], 7 'shop _ IMG '=> $ shop_obj [0] ['goods _ IMG'], 8 'shop _ price' => $ shop_obj [0] ['price'], 9 'shop _ old_price '=> $ shop_obj [0] ['old _ price'] 10 ); 11 # The reason for Array serialization is that the cookie can only store strings 12 $ cookie_data = serialize ($ cookie_array); 13 # store cookie14 setcookie ("cookie_data", $ cookie_data, time () + 3600 ); 15 # retrieve the cookie and serialize 16 $ data_info = unserialize ($ _ cookie ['cookie _ data']); 17 var_dump ($ data_info ); 18 19 20 21 # After serialization 22 A: 5: {s: 7: "shop_id"; s: 1: "4"; s: 9: "shop_name"; s: 37: "[4 stores general] butterfly flower Cafe"; s: 8: "shop_img"; s: 18: "14084523762428.jpg"; s: 10:" shop_price "; s: 4: "79.0"; s: 14: "shop_old_price"; s: 5: "214.0 ";} 23 24 #25 array26 (27 [shop_id] => 428 [shop_name] => [4 store General] butterfly flower cafe 29 [shop_img] => 14084523762428.jpg 30 [shop_price] => 79.031 [shop_old_price] => 214.032)
CI cookie storage array