File: arraySearch.example.php

Recommend this page to a friend!
  Classes of Matthew Knowlton  >  Array Search  >  arraySearch.example.php  >  Download  
File: arraySearch.example.php
Role: Example script
Content type: text/plain
Description: Example File
Class: Array Search
Search and filter array data using MySQL database
Author: By
Last change:
Date: 6 years ago
Size: 1,679 bytes
 

Contents

Class file image Download
<pre>
<?php

require_once('arraySearch.class.php');

// API call (or whatever) for data
$response = json_decode(file_get_contents('arraySearch.example.data.php'),true);

/*********************************************/

// Initialize arraySearch Object
//$mysqli = new mysqli($server, $user, $pass, $db);
$arraySearch = new arraySearch($mysqli);

// Assign object an array
$arraySearch->todoList = $response['todos'];
// Note: this array can be ($incrementer => $field) or ($field => $incrementer)
// the result will be returned in the same format it was supplied in.

/*********************************************/

// Now we can start reading out, this will print all the data we just put in
echo '<br/> Example 1: Printing all the data<br/>';
print_r($arraySearch->todoList->data());

/*********************************************/

// Or we could run the data through a filter
echo '<br/> Example 2.0: Using filters on the data<br/>';
print_r($arraySearch->todoList->filterBy(['Priority' => '10'])->data());

// We can also use WildCards and Inclusive Arrays in these filters
echo '<br/> Example 2.1: Using wildcards in the filters<br/>';
print_r($arraySearch->todoList->filterBy(['Description' => '%important%', 'Priority' => ['8','9','10']])->data());

/*********************************************/

// We also have the ability to modify the data in the object, before or after the filter
echo '<br/> Example 3: Modifying data after the filter<br/>';
print_r($arraySearch->todoList->filterBy(['Priority' => ['1','2','3','4']])->modify(['Priority' => '5'])->data());

/*********************************************/

?>
</pre>

For more information send a message to info at phpclasses dot org.