我有其中存儲關聯數組PHP訪問值,可以快速的Arrray持物,其中對象中的一個元件具有一個數組
目的包括
class mainObj {
public $name = 0;
public $address = '';
public $someArray = array();
}
這些對象存儲在一個對象陣列。
objArray[] = obj1;
objArray[] = obj2
我的問題是: 我最好,很容易如何可以訪問它本身存儲在另一個數組對象內部的關聯數組的鍵和值?
我可以回去通過迭代得到鍵和值...
for ($i=0; $i<count($objArray); $i++)
{
$tempArray = $objArray[$i]->someArray;
foreach ($tempArray as $key => $value)
{
echo "Key: $key; Value: $value\n";
}
}
重新編寫的對象是一個數組在這個階段可能是問題太多......
在PHP中,有沒有更快的方法來訪問存儲關聯數組的對象數組中的關聯數組鍵和值?
衷心感謝你對你的答案提前... 馬福
'$ objArray [$ i] - > someArray [$ key];'? –
對不起,如果這個問題冒犯了你......也許我可以稍微說一下這個問題......我在第一時間發佈問題之前嘗試了你的建議,它並沒有給我一個數組或值的關鍵,這就是我首先提出這個問題的原因。 – Marv
你可以實現[ArrayAccess](http://www.php.net/manual/en/class.arrayaccess.php) – bitWorking