PHP code example of craigh / jmespath-iterator
1. Go to this page and download the library: Download craigh/jmespath-iterator 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/ */
craigh / jmespath-iterator example snippets
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator([
'foo' => [
'bar' => [
'baz' => 'qux',
],
],
]);
echo $iterator['foo.bar.baz']; // output: 'qux'
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator([
'people' =>
[
[
'first' => 'James',
'last' => 'd',
],
[
'first' => 'Jacob',
'last' => 'e',
],
[
'first' => 'Jayden',
'last' => 'f',
],
[
'missing' => 'different',
],
],
'foo' =>
[
'bar' => 'baz',
],
]);
var_dump($iterator['people[*].first']); // output: ["James", "Jacob", "Jayden"]
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator([
[
'foo' => [
'bar' => 'qux',
],
],
]);
echo $iterator[0]['foo.bar']; // output: 'qux'
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator([
[
'bar' => [
'baz' => 'qux',
],
],
[
'bar' => [
'baz' => 'qux',
],
],
]);
if(count($iterator)){
foreach ($iterator as $value) {
echo $value['bar.baz'];
}
}
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator();
$iterator[] = 'foo';
$iterator[] = 'bar';
echo $iterator[1] // output: 'bar';
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator(['foo','bar','baz','qux', 'qux']);
var_dump($iterator['0::2']); // outputs: ['foo', 'baz', 'qux']
var_dump($iterator['[0::2]']); // outputs: ['foo', 'baz', 'qux']
use Humps\Jmespath\JmespathIterator;
$iterator = new JmespathIterator(['foo','bar','baz','qux', 'quxx']);
$array = $iterator->toArray();
natsort($array);
$newIterator = new JmespathIterator($array);
var_dump($newIterator); // outputs: ['bar', 'baz','foo', 'qux', 'quxx']