AbstractNode::insertChildAtPosition

The insertChildAtPosition() method inserts a child node at a specific position relative to the target node's children, defined by the offset value. This allows for precise control over the node placement within the parent node's child list.

The offset parameter defines the index where the new node will be inserted. A value of 0 places the node at the beginning of the NodeList, positive values insert the node further down, and negative values place the node closer to the end.

Description

public AbstractNode::insertChildAtPosition(int $offset, NodeInterface $node): ?NodeInterface

Parameters

offset

An int representing the index where the new node should be inserted.

  • 0: Insert at the beginning of the child nodes
  • Positive integers: Insert at the specified index
  • Negative integers: Insert relative to the end of the NodeList

node

The NodeInterface instance to insert.

Return Value

Returns the inserted NodeInterface instance if successful, null otherwise.

Exceptions

None

Source Code
If you find this project useful, consider leaving a on GitHub! Thank you!