我知道我可以这样添加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