我经常遇到这种情况:
foreach ($someObjects as &$someObject)
{
$someObjectsIndex[$someObject->id] = $someObject;
}
和这个:
$thingsIActuallyWant = [];
foreach ($associativeList as &$associativeItem)
{
$thingsIActuallyWant[] = $associativeItem['id'];
}
我想知道是否有现有的方法或其他东西可以更短地编写这些东西,而无需编写 foreach 循环。