Minwork Array
  • Minwork Array
  • Common methods
    • has
    • get → getNestedElement
    • set → setNestedElement
    • remove
    • clone
    • getKeysArray
  • Object oriented methods
    • General information
  • Traversing array
    • Finding
    • Iterating
  • Manipulating array
    • Mapping
    • Filtering
    • Grouping
    • Sorting
    • Computations
    • Flattening
  • Validating array
    • check
    • isEmpty
    • isNested
    • isArrayOfArrays
    • isAssoc
    • isUnique
    • isNumeric
    • hasKeys
  • Utility methods
    • pack
    • unpack
    • createMulti
    • forceArray
    • getDepth
    • random
    • shuffle
    • nth
    • getFirstKey
    • getLastKey
    • getFirstValue
    • getLastValue
Powered by GitBook
On this page

Was this helpful?

  1. Utility methods

createMulti

Definition

Arr::createMulti(array $keys, ?array $values = null): array

Description

Create multidimensional array using either first param as config of keys and values or separate keys and values arrays

Examples

Arr::createMulti([
    'test.[]' => '123',
    'test.test2.test3' => 'abc',
    'test.test2.[]' => 567,
    'test.[].1' => 'def',
]) ->
[
    'test' => [
        '123',
        'test2' => [
            'test3' => 'abc',
            567
        ],
        [
            1 => 'def'
        ],
    ]
]

Arr::createMulti([
     ['test', '[]'],
    ['test', 'test2', 'test3'],
    ['test', 'test2', '[]'],
    ['test', '[]', 1],
], [
     '123',
    'abc',
    567,
    'def',
]) ->
[
    'test' => [
        '123',
        'test2' => [
            'test3' => 'abc',
            567
        ],
        [
            1 => 'def'
        ],
    ]
]

// In case of empty keys argument simply return new empty array
Arr::createMulti([]) -> []
PreviousunpackNextforceArray

Last updated 5 years ago

Was this helpful?