PHP code example of boxblinkracer / xpatharray

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

    

boxblinkracer / xpatharray example snippets



//...
$customer = array(...)

# xpath array with / as our delimiter
$xCustomer = new XPathArray('/', $customer);

# object/array access with XPathNotFoundException
/** @var array @address */
$address = $xCustomer->get('/address');

# multi level access
$phoneMobile = $xCustomer->get('/contact/phone/mobile');

# type safe access with internal conversion
$street = $xCustomer->getString('/street');
$streetNumber = $xCustomer->getInt('/streetNr');
$isCompany = $xCustomer->getBool('/isCompany');
$customerRevenue = $xCustomer->getFloat('/revenue/total');


//...
$customer = array(...)

# xpath array with / as our delimiter
$xCustomer = new XPathArray('/', $customer);

# multi level access
$phoneMobile = $xCustomer->get('/contact/phone/mobile', '-');

# type safe access with internal conversion
$street = $xCustomer->getString('/street', '-');
$streetNumber = $xCustomer->getInt('/streetNr', 0);
$isCompany = $xCustomer->getBool('/isCompany', false);
$customerRevenue = $xCustomer->getFloat('/revenue/total', 0.0);