PHP Classes

Array Search: Search and filter array data using MySQL database

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 581 All time: 5,314 This week: 123Up
Version License PHP version Categories
array-search 1.1Public Domain5PHP 5, Databases, Searching, Data types


This class can search and filter array data using MySQL database.

It can take an array of associative array records and inserts them in a MySQL database.

The class then uses SQL queries to search, filter and sort records using SQL query clauses. This allows the user to use SQL's wildcard and inclusive array search features.

Innovation Award
PHP Programming Innovation award winner
August 2015

Prize: PhpStorm IDE personal permanent license
PHP provides basic support for searching values in arrays. It would be better if it provided means to search data as SQL databases.

This class provides a solution that leverages the power of SQL databases to provide more flexible array filtering and sorting capabilities.

Despite for small arrays it may much slower than searching arrays in memory, for large arrays it may be a more feasible solution, as it will not require to load the whole arrays in memory to search for their values.

Manuel Lemos
Picture of Matthew Knowlton
  Performance   Level  
Name: Matthew Knowlton is available for providing paid consulting. Contact Matthew Knowlton .
Classes: 6 packages by
Country: United States United States
Age: 28
All time rank: 2036290 in United States United States
Week rank: 225 Up30 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x




// API call (or whatever) for data
$response = json_decode(file_get_contents(''),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/>';


// 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());



  Files folder image Files  
File Role Description
Plain text file arraySearch.class.php Class Class Source
Accessible without login Plain text file arraySearch.example.php Example Example File
Accessible without login Plain text file Data data for search example

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:5,314
This week:123Up