PHP code example of alexrili / phmap

1. Go to this page and download the library: Download alexrili/phmap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexrili / phmap example snippets


[
    "from" =>"a",
    "to" => "b" 
]

[
    "from" =>"a.a1.+.a.a2",
    "to" => "b" 
]

[
    "from" =>"__(This is a fixed value)__",
    "to" => "b" 
]

[
    "from" =>"a.*.a1",
    "to" => "b.*.b1" 
]

[
    "from" =>"a||a1",
    "to" => "b" // if finds value in [a], brings [a], if not try to brings [b]
]

[
    "from" =>"a",
    "to" => "b" 
    "nullable" => "true" 
    // if [a] don't have value
    // the results will be ["b"=>null] 
]


$inputData = [
    'a' => [
        [
            'ac1' => 'I`m a multilevel value'
        ],
        [
            'ac1' => 'I`m a multilevel value',
        ]
    ],
    'aDV' => 'I`m a directed value'
];

$map = [
    [
        'from' => 'a.*.ac1.+.__(I`m a fixed value)__.+.aDV',
        'to' => 'b.*.bc'
    ]
];

$response = payload_map($inputData, $map);

// var_dump($response)
// result wil be
array:1 [
  "b" => array:2 [
    0 => array:1 [
      "bc" => "I`m a multilevel valueI`m a fixed valueI`m a directed value"
    ]
    1 => array:1 [
      "bc" => "I`m a multilevel valueI`m a fixed valueI`m a directed value"
    ]
  ]
]