我在
PHP中有这个:
$units = array(); foreach ($popPorts as $port) { $units[$port->getFrameNo()][$port->getSlotNo()][$port->getPortNo()] = $port->getPortNo(); }
我怎样才能在树枝上实现同样的目标?
到目前为止我试过这个:
{% set frames = [] %} {% for row in object.popPorts %} {% set frames[row.frameNo][row.slotNo][row.portNo] = row.portNo %} {% endfor %} {{ dump(frames) }}
但后来我收到一个错误:
Unexpected token “punctuation” of value “[” (“end of statement block”
expected).
输出应该是这样的:
array (size=3) (frame) 1 => array (size=2) (slot) 1 => array (size=4) 0 => (port) 26 1 => (port) 27 2 => (port) 28 3 => (port) 29 (slot) 5 => array (size=2) 0 => (port) 31 1 => (port) 34 (frame) 2 => array (size=1) (slot) 3 => array (size=1) 0 => (port) 32 (frame) 3 => array (size=1) (slot) 6 => array (size=1) 0 => (port) 33