PHP Classes
elePHPant
Icontem

File: examples/sum.php

Recommend this page to a friend!
  Classes of Nahid Bin Azhar  >  PHP JSON Query  >  examples/sum.php  >  Download  
File: examples/sum.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP JSON Query
Query JSON data to find and extract information
Author: By
Last change:
Date: 10 months ago
Size: 636 bytes
 

Contents

Class file image Download
<?php
/**
 * Example: sum($column = null)
 * ================================
 *
 * sum() method return summation of resulting data
 */

require_once '../vendor/autoload.php';

use
Nahid\JsonQ\Jsonq;

$q = new Jsonq('data.json');

try {
   
$res = $q
       
->from('products')
        ->
where('cat', '=', 2)
        ->
sum('price');

   
//from plain array collection
   
$res1 = $q->collect([2, 10, 1, 5, 7])
            ->
sum();
   
dump($res, $res1);
} catch (\
Nahid\JsonQ\Exceptions\ConditionNotAllowedException $e) {
    echo
$e->getMessage();
} catch (\
Nahid\JsonQ\Exceptions\NullValueException $e) {
    echo
$e->getMessage();
}