epiclesys/value-matcher

1.0.3 2024-09-06 23:13 UTC

This package is auto-updated.

Last update: 2025-04-07 00:27:11 UTC


README

Latest Stable Version License

A simple PHP library for searching json values inside json or sub-arrays inside arrays.

Installation

You can install this package via Composer:

composer require epiclesys/value-matcher

Mach json values inside other json

Say we need to check if this json value

{ "key" : ["value"] };

is contained somewhere here

{
  "level9": {
    "finalLevel": "reached",
    "stillGoing": true,
    "data" : { "key" : ["one", 2, "value"] }
  }
}

Usage

 <?php
 
 require __DIR__ . '/vendor/autoload.php';
 
 use Epiclesys\ValueMatcher\JsonMatcher; 
 
 $needle = '{ "key" : ["value"] }';
 $haystack = '
 {
    "level9": {
    "finalLevel": "reached",
    "stillGoing": true,
    "data" : { "key" : ["one", 2, "value"] }
    }
 }';
 
 JsonMatcher::contains($needle, $haystack); // true

Similarly works for matching array values inside another array

 ArrayMatcher::contains($needle, $haystack); // true

This project is licensed under the MIT License.