\Phabstractic\ResourceArrayUtilities

The Static Array Utility Class

This class contains all the static array-based utility functions that are used in particular cases throughout the library.

CHANGELOG

1.0: Documented Utility - October 7th, 2013 2.0: Refactored into Primus/Falcraft - April 10th, 2015 2.0.1: Added returnUniqueByReference - April 10th, 2015 3.0: Inherited from Zend\Stdlib\ArrayUtils - April 12th. 2015 3.1: Modified elementComparison for further compatibility - April 14th, 2015 4.0: returnUnique now returns appropriate data objectToArray now includes values reformatted for inclusion in phabstractic - July 8th, 2015

Summary

Methods
Properties
Constants
returnUnique()
returnUniqueByReference()
elementComparison()
objectToArray()
arrayToObject()
arrayChangeValueCase()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

returnUnique()

returnUnique(array  $data,   $assoc = false) : array

Return Unique (array)

This can be used as an alternative to array_unique when that built-in function doesn't seem to work for your purposes. This is not recusrive but should work on associative arrays (though, haphazardly)

Version 4: Compatible with PHP 7 Added associative option as second default argument

Parameters

array $data

The given data to sort

$assoc

Returns

array —

The unique array, this DOES NOT alter the argument

returnUniqueByReference()

returnUniqueByReference(array  $data,   $assoc = false) : array

Return Unique (array)

This can be used as an alternative to array_unique when that built-in function doesn't seem to work for your purposes. This is not recusrive but should work on associative arrays (though, haphazardly)

Version 4: Compatible with PHP 7 Added associative option as second default argument

Parameters

array $data

The given data to sort

$assoc

Returns

array —

The unique array, THIS DOES ALTER the argument

elementComparison()

elementComparison(mixed  $a, mixed  $b) : integer

Compare Array Elements in an Object Compatible Sense

This is an attempt to compare unknown objects in an array to each other. The idea is that one object will have the same hash even if referenced in different places, and that that hash will be different from other object's. It seems to work okay.

Parameters

mixed $a

The first element

mixed $b

The second element (imagine in an equality test)

Returns

integer —

0, 1, or -1

objectToArray()

objectToArray(object  $o) : array

A utility function for converting a stdClass object to an array

This could also work on other objects as well, precariously, but it's designed for turning stdClass objects into arrays

Version 4: Compatible with PHP 7 Now includes values

Parameters

object $o

The given object to convert

Returns

array —

The converted array

arrayToObject()

arrayToObject(array  $v) : \Phabstractic\Resource\stdClass

Convert an array into a stdClass object

Converts an array to a simple object

Parameters

array $v

The given array to convert

Returns

\Phabstractic\Resource\stdClass —

The returned converted object

arrayChangeValueCase()

arrayChangeValueCase(array  $input, integer  $case = CASE_LOWER) : array

Change the case of the values of an array

Like array_change_key_case except for values, defaults to CASE_LOWER, but CASE_UPPER can be used as well.

NOTE: Using recursion, this processes the given array recursively.

Parameters

array $input

The array to use as input

integer $case

CASE_LOWER or CASE_UPPER

Returns

array —

An array with the values all cased