PHP code example of guglielmopepe / recursivecallbackmapiterator

1. Go to this page and download the library: Download guglielmopepe/recursivecallbackmapiterator 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/ */

    

guglielmopepe / recursivecallbackmapiterator example snippets





/**
 * Callback for RecursiveCallbackMapIterator
 *
 * @param $current   Current item's value
 * @param $key       Current item's key
 * @param $iterator  Iterator being filtered
 * @return mixed     The item after it has been applied the callback function
 */
function my_callback($current, $key, $iterator)
{
    // Your code here
}





$data = ['foo'=>['foo','bar'],'bar'=>['bar','foo']];

// A callback
function my_callback($current, $key, $iterator)
{
    if ($key % 2 == 0)
    {
        return $current;
    }

    return \strtoupper($current);
}

// Applies callback
$iterator = new \RecursiveCallbackMapIterator\RecursiveCallbackMapIterator(new \RecursiveArrayIterator($data), 'my_callback');