add a method to NestedArray that does array_walk_recursive but passes the parents to the callback

Created on 2 December 2022, almost 3 years ago
Updated 14 June 2023, over 2 years ago

Problem/Motivation

PHP's array_walk_recursive allows you to work through a nested array, but the callback you pass only gets the key of the current level's array. The callback doesn't know where in the array it is currently operating.

This is sometimes useful, such as when working with FormAPI values.

E.g. suppose we have a nested array of values:

[
    'one' => 1,
    'nest' => [
      'two' => 2,
      'three' => 3,
    ],
]

and we want to set them all as #default_values in a $form array which has the same structure. We can't use array_walk_recursive() because the callback can't know that the value 3 belongs in $form['nest']['three'], because the callback just gets the $key of 'three'.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Feature request
Status

Needs work

Version

11.0 🔥

Component
Base 

Last updated about 2 months ago

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024