我知道我可以這樣添加elemnts到一個數組:使用PHP中的鍵/值將元素添加到數組中?
$arr = array("foo" => "bar", 12 => true);
現在,我怎麼能做到這一點在foreach使用動態值?我有這樣的代碼:
foreach ($values as $value) {
$imagePath = $value->getImagePath();
$dependsOn = $value->getDependsOn();
$dependsOn = explode(':', $dependsOn);
$dependsOnOptionValueTitle = trim($dependsOn[1]);
array_push($paths, $dependsOnOptionValueTitle => $imagePath); // not working
}
如何,我可以添加鍵/值對我$paths
陣列?
http://php.net/array – hakre 2012-07-01 13:46:43