好的,所以我想知道第二个值的关键是什么,这样我才能得到所说的价值。 所以我希望能够从newsId获得“5”或“4”。因此访问第一个数组将是$ array [0]但是只访问“5”的键是什么?
这是vardump
array(5) { [0]=> object(NewsArticleBase)#6 (7)
{ ["newsId:private"]=> string(1) "5" ["newsTitle:private"]=> string(41) "XCR'14 Round 5 Sandown Road Relay Champs!" ["newsPreview:private"]=> string(243) " Teams compete on the fast Sandown course for the honour of the Victorian Road Relay Championship.Two laps of the motor racing circuit make for 6.2km legs for open and overage competitors, whilst the juniors race over one lap of 3.1km." ["newsDisplayPicture:private"]=> string(57) "images/10464246_236382816571109_6852705680507428565_n.jpg" ["newsContent:private"]=> string(6) "asdsad" ["newsCategories:private"]=> string(21) "Long Distance Running" ["newsSubmissionDate:private"]=> string(19) "2014-07-24 11:33:32" }
[1]=> object(NewsArticleBase)#7 (7)
{ ["newsId:private"]=> string(1) "4" ["newsTitle:private"]=> string(52) "XCR'14 Round 4 Everyones favourite course Bundoora!!" ["newsPreview:private"]=> string(402) "Selection Trial for the Australian Cross Country Championships This bumper day of cross country racing incorporates the All Schools Cross Country Championships and also serves as the selection trial for the Australian Cross Country Championships. The open and overage men’s race covers 12km of the gruelling slopes of Bundoora Park, while the women’s race covers 8km. Juniors race over 3km, 4km or 6km." ["newsDisplayPicture:private"]=> string(22) "images/displaypicture2" ["newsContent:private"]=> string(8) "asdgfdsg" ["newsCategories:private"]=> string(21) "Long Distance Running" ["newsSubmissionDate:private"]=> string(19) "2014-07-24 11:32:09" }
答案 0 :(得分:0)
在var_dump
中,密钥列为[key] => type(variable){ value }
所以
array(2) {
[0]=> object(NewsArticleBase)#6 (7) { ["newsId:private"]=> string(1) "2" }
[1]=> object(NewsArticleBase)#7 (7) { ["newsId:private"]=> string(1) "1" }
}
您有array[0]
和array[1]
现在,如果属性为public
,您可以array[0]->property
,但在您的情况下,他们会private
。因此,您需要一个可以访问它并返回值的方法(如getVar()
)。