{{ set userIds = {} }}
{% for user in users %}
...
{% set userIds = userIds|merge({id : user.id} %}
...
{% endfor %}
如何访问代码中使用的任何foreach的$ loop?
答案 0 :(得分:12)
您可以使用import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial.distance import cdist
# Mean
M = [10, 7]
# Covariance matrix
V = np.array([[ 9, -2],
[-2, 2]])
# Generate a sample from the multivariate normal distribution
# with mean M and covariance matrix V.
np.random.seed(314159)
x = np.random.multivariate_normal(M, V, size=250)
# Compute the Mahalanobis distance of each point in the sample.
mdist = cdist(x, [M], metric='mahalanobis', V=V)[:,0]
# Find where the Mahalanobis distance is less than 2.
d2_mask = mdist < 2
x2 = x[d2_mask]
plt.plot(x2[:,0], x2[:,1], 'o',
markeredgecolor='r', markerfacecolor='w', markersize=6, alpha=0.6)
plt.plot(x[:,0], x[:,1], 'k.', markersize=5, alpha=0.5)
plt.grid(alpha=0.3)
plt.axis('equal')
plt.show()
访问当前循环的父循环。
答案 1 :(得分:1)
就我而言(Laravel 6.8)$loop->parent
看起来像这样
[
{"iteration":1,"index":0,"remaining":1,"count":2,"first":true,"last":false,"odd":true,"even":false,"depth":1,"parent":null},
{"iteration":2,"index":1,"remaining":0,"count":2,"first":false,"last":true,"odd":false,"even":true,"depth":1,"parent":null}
]
访问父索引$loop->parent->index