1

I have:

array:2 [
  0 => array:1 [
    "FNAME" => "nullable|string"
  ]
  1 => array:1 [
    "LNAME" => "nullable|string"
  ]
]

And I try to get:

array:1 [
  "key" => "value"
]

I try map it, but has problem

0

2 Answers 2

2
<?php
$array = [
    [
        "FNAME" => "nullable|string",
    ],
    [
        "LNAME" => "nullable|string",
    ]
];

$newArray = [];

foreach ($array as $item) {
    foreach ($item as $key => $value) {
        $newArray[$key] = $value;
    }
}

print_r($newArray);

Will output:

Array
(
    [FNAME] => nullable|string
    [LNAME] => nullable|string
)
Sign up to request clarification or add additional context in comments.

Comments

1

Two simple ways:

print_r(array_merge(...$arr));
// if `...` is not available (php < 5.6), then:
print_r(call_user_func_array('array_merge', $arr))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.