Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data = [
- 'content/price/value' => 10.01,
- 'content/price/currency' => 'USD',
- 'content/shipping/free' => false,
- 'content/descrtiption' => 'hallo meine name ist dominik stapf',
- 'content/erp_name/0/locale' => 'en_US',
- 'content/erp_name/0/scope' => null,
- 'content/erp_name/0/data' => 'Jack',
- 'content/erp_name/1/locale' => 'de_DE',
- 'content/erp_name/1/scope' => 'NULL',
- 'content/erp_name/1/data' => 'Jacke'
- ];
- $result = [];
- foreach ($data as $structure => $value) {
- $reference = &$result;
- $nodes = explode('/', $structure);
- foreach ($nodes as $node) {
- if (!isset($reference[$node])) {
- $reference[$node] = [];
- }
- $reference = &$reference[$node];
- }
- $reference = $value === 'NULL' ? null : $value;
- }
- echo json_encode($result, JSON_PRETTY_PRINT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement