John Davidson

php - Create array of mapped array keys

0 comments
Message:


I am trying to create an array which shows the layout of an array.


This would be the input:


    $array = [
'company' => [
'contacts' => [
'first_names',
'last_name',
'emails',
'phones' => [
'test'
]
],
'addresses' => [
'postal_code'
],
]
];

And this is what I am trying to get the output to look like:


    $array = [
'company.contacts.phones'
'company.addresses'
];

I have been trying to work this out for hours but haven't manages to come up with a solution. It needs to work with any layout/depth of input array.



My Answer:
> 'Google',_ 'location' => 'Mountain View',_ 'employees' => 10000,_ 'revenue' => 1000000000,_ ];_And this would be the desired output:_ $mappedArray = [_ 'company',_ 'location',_ 'employees',_ 'revenue',_ ];_I am trying to achieve this by using the array_keys() function in PHP, but I am not sure how to map the keys to the desired output array.

Rate this post

4 of 5 based on 7357 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us