PHP code example of x-o-r / walker

1. Go to this page and download the library: Download x-o-r/walker 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/ */

    

x-o-r / walker example snippets


(new Walker)
    ->from(
        (object)["Foo" =>
            (object)["Bar" => "Value"]
        ])
    ->with('Foo->Bar')
    ->asString();
  
/* Will return 'Value' */

     
(new Walker)
    ->fromJson('{
        "Foo": {
            "Bar": "Value"
           }
       }')
    ->with('Foo->Bar')
    ->asString();
  
/* Will return 'Value' */

     
(new Walker)
    ->from([
        (object)["Foo" =>(object)["Bar" => "Some"]],
        (object)["Walker" =>(object)["Texas" => (object)["Ranger" => "values"]]]
    ])
    ->with('Foo->Bar')
    ->with('Walker->Texas->Ranger')
    ->asString();
  
/* Will return 'Some, values' */

           
(new Walker)
    ->from([
        (object)["Walker" =>
            (object)["Texas" =>
                (object) ['Ranger' => 'All']
            ]
        ],
        (object)["Walker" => [
                (object)["Texas" => (object)["Ranger" => "targets"]],
                (object)['Texas' => (object)['Ranger' => 'are']],
            ]
        ],
        (object)['Walker' => (object)['Texas' => (object)['Ranger' => 'retrieved']]]
    ])
    ->with('Walker->Texas->Ranger')
    ->asString(function($founds) {
        return join(' ', $founds);
    });
  
/* Will return 'All targets are retrieved' */