2012-04-05 48 views
2

我有課,我想initalize與類型「斑點」存儲線框圖列,但我不知道怎麼辦?看看代碼的緯線如何初始化圖片「斑點」形構造PHP

public function __construct($data=array()) { 
    if (isset($data['id'])) $this->id = (int) $data['id']; 
    if (isset($data['date'])) $this->date= (int) $data['date']; 
    if (isset($data['topic'])) $this->topic = preg_replace ("/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['topic']); 
    if (isset($data['author'])) $this->author = preg_replace ("/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['author']); 
    if (isset($data['content'])) $this->content = $data['content']; 
    if (isset($data['picture'])) $this->picture ="Here sholud be the Type" $data['picture']; 
    } 
+0

初始化它作爲字符串存儲。 – 2012-04-05 05:37:16

+0

http://php.net/manual/language.types.type-juggling.php – 2012-04-05 06:03:23

回答

3

在PHP中,二進制數據也存儲在字符串中。

所以簡單地用$this->picture = $data['picture'];

+2

換句話說,PHP的字符串其實只是字節數組。 – deceze 2012-04-05 05:45:24

+0

謝謝@ThiefMaster和deceze – Iman25 2012-04-05 05:54:03

+0

@ Iman25:請不要忘記接受這個答案,如果它通過點擊這個答案左側的灰色顯示選中圖標幫助你。 – ThiefMaster 2012-04-05 06:03:34