2015-08-26 44 views
-2

我正在面臨問題以檢索數組後的值。請讓我知道我怎麼能得到那個。我想得到第一個值'[_answer]'從數組中獲取問題以檢索值

WpProQuiz_Model_AnswerTypes Object 
    (
    [_answer:protected] => new1 
    [_html:protected] => 
    [_points:protected] => 1 
    [_correct:protected] => 
    [_sortString:protected] => 
    [_sortStringHtml:protected] => 
    [_mapper:protected] => 
) 

    Basically i am trying to getting data from serialize data and after unserialize it is showing above output: 

    a:4:{i:0;O:27:"WpProQuiz_Model_AnswerTypes":7: {s:10:"*_answer";s:4:"new1";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:1;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:4:"new2";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:1;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:2;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:4:"new3";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:3;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:4:"new4";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}} 

回答

0

這是一個對象,而不是數組。 您有兩種方法可以訪問它的屬性。

您可以使用echo WpProQuiz_Model_AnswerTypes->_answer

或將其轉換爲一個數組這樣

$asArray = (array)WpProQuiz_Model_AnswerTypes; 
echo $asArray['_answer']; 
+0

我已經嘗試過了,它不工作 – ankpro23

+0

你得到一個錯誤信息(或通知),什麼錯誤你得到的消息? – Paladin

+0

致命錯誤:無法訪問受保護的屬性WpProQuiz_Model_AnswerTypes :: $ _ answer – ankpro23