2

I would like remove key [Properties] from array like below

I have it:

Array(
 [Values] => 1
 [List] => Array(
     [Product] => Array( 
         [Details] => Array( 
            [Properties] => Array( 
                [Id] => 1
            )
         )
     )
  )
)

And I would like to remove [properties] :

Array(
  [Values] => 1
  [List] => Array(
    [Product] => Array( 
        [Details] => Array( 
            [ID] => 1
        )
     )
  )
)

I tried:

$result = array_map(function($sub) { return $sub['Properties']; }, $array);

and

$array= array_column($array, 'Properties');

Unfortunately it doesn't work. How can I do this ?

3
  • Can you edit your example input to show the structure when it has more than one entry? Commented Sep 25, 2017 at 16:40
  • use unset() as in unset($myarray['properties']) Commented Sep 25, 2017 at 16:43
  • @RobertRocha - it also doesn't work Commented Sep 25, 2017 at 16:47

1 Answer 1

2

Straight-forwardly:

$arr = [
    "Values" => 1,
    "List" => ["Product" => [ "Details" => ["Properties" => ["Id" => 1] ] ] ]
];

$arr['List']['Product']['Details']['Id'] = $arr['List']['Product']['Details']['Properties']['Id'];
unset($arr['List']['Product']['Details']['Properties']);

print_r($arr);

The output:

Array
(
    [Values] => 1
    [List] => Array
        (
            [Product] => Array
                (
                    [Details] => Array
                        (
                            [Id] => 1
                        )
                )
        )
)
Sign up to request clarification or add additional context in comments.

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.