使用php对象访问多个数组

使用php对象访问多个数组,php,arrays,Php,Arrays,好了,伙计们,我想知道第二个值的关键是什么,这样我就可以得到这个值。 所以我希望能够从newsId获得5或4。因此,访问第一个数组需要$array[0],但访问5的关键是什么 这是垃圾场 array(5) { [0]=> object(NewsArticleBase)#6 (7) { ["newsId:private"]=> string(1) "5" ["newsTitle:private"]=> string(41) "XCR'14 Round 5 Sandown Roa

好了,伙计们,我想知道第二个值的关键是什么,这样我就可以得到这个值。 所以我希望能够从newsId获得5或4。因此,访问第一个数组需要$array[0],但访问5的关键是什么

这是垃圾场

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" }
在var_转储中,键列为[key]=>typevariable{value}

所以

您有数组[0]和数组[1]


现在,如果属性是公共的,您可以只执行array[0]->property,但在您的情况下,它们是私有的。因此,您需要一个像getVar这样的方法来访问它并返回值。

它只是数组[1]?不,这是第二个值。我已经缩短了实际代码的长度,只是想在这个数组中会有很多对象,这是一个多维数组,我想知道如何进入第二个和/或第三个键以获得该值。然后您需要提供示例数据供我们使用。完成后,刷新页面。这是一个带有对象的多维数组。为了便于阅读,我把它缩短了。
array(2) { 
    [0]=> object(NewsArticleBase)#6 (7) { ["newsId:private"]=> string(1) "2" }
    [1]=> object(NewsArticleBase)#7 (7) { ["newsId:private"]=> string(1) "1" }
}