Skip to content

Allow multidimensional array as another return value option for WireArray::each(), WireArray::explode() #571

@ethnoxcom

Description

@ethnoxcom

Current implementation always return an array of key/value. The following code:

$companies = $pages->find("template=company, parent=/companies/, limit=10")->explode([
    "title",
    "contact.person",
    "contact.email",
    "address.city", 
    "address.state",
    "address.zip"
    ]);

will return this array for each item:

0 => [
    'title' => 'ProcessWire, Inc.'
    'contact.person' => 'John Doe'
    'contact.email' => '[email protected]'
    'address.city' => 'Melbourne Beach'
    'address.state' => 'FL'
    'address.zip' => '32951'
]

otherwise if I use the following:

$companies = $pages->find("template=company, parent=/companies/, limit=10")->explode([
    "title",
    "contact[]",
    "address[]"
    ]);

I will get the whole WireArray for contact and address field like:

0 => [
    'title' => 'ProcessWire, Inc.'
    'contact[]' => WireArray
    'address[]' => WireArray
]

The feature that I propose is to allow this:

$companies = $pages->find("template=company, parent=/companies/, limit=10")->explode([
    "title",
    "contact[person, email]",
    "address[city, state, zip]"
    ]);

with a return array like:

0 => [
    'title' => 'ProcessWire, Inc.'
    'contact' => [
        'person' => 'John Doe',
        'email' => '[email protected]'
    ],
    'address' => [
        'city' => 'Melbourne Beach',
        'state' => 'FL',
        'zip' => '32951'
    ]
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions