PHP Classes
elePHPant
Icontem

Array Depth: Traverse arrays in depth to perform useful actions

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-04-16 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 156 All time: 8,525 This week: 395Up
Version License PHP version Categories
array_depth 1.0.1Custom (specified...5PHP 5, Data types
Description Author

This class can traverse arrays in depth to perform useful actions. Currently it can:

- Determine the depth of a nested array
- Retrieve all data types used in an array
- Determine whether or not an array is homogeneous
- Compute the signature of an array
- Determine whether or not an array is suitable for the process of selection of rows and columns

Innovation Award
PHP Programming Innovation award nominee
February 2018
Number 3
Arrays are a very popular data type in PHP because they make it easy to associate key names or numbers with the respective values.

They also allow to nest information by storing arrays as key values.

This package can inspect nested arrays and perform several types useful operations like checking if all the stored values is of the same type, compute an unique value from all the array values that can be used as a signature of the array, determine if the array can be used as a table with rows and columns

Manuel Lemos
  Performance   Level  
Name: zinsou A.A.E.Moïse <contact>
Classes: 45 packages by
Country: Benin Benin
Innovation award
Innovation award
Nominee: 17x

Winner: 2x

Details
This  class can help achieving this goal:

	- return the given  array depth (level of interleaving) 
	- return all data types used in a given array 
	- return  whether or not the array is homogeneous 
	- return the signature of a given array 
	- return whether or not an array is suitable for rows and columns selection's process.
	
	
	for example when you need to do some recursive foreach on an array without knowing the array ,it
	may be useful to know the real depth programmatically.
	
	it may be useful to know all data types used in an array or even just in the first element of an array
	as you may see in the homogeneous method implementation.
	
	
	An array must be homogeneous in many applications: for example : to compute a chi square value for a data's cross table, 
	all values must be integer(may be double number but without floating point/comma) so if there is  any double value in this array 
	the result will be corrupted.
	
	when you will use array_column on an array for some operations ,it is impossible to be sure that all cells exists
	so you got some incomplete results for example 
	
	$array=array(array(1,2,3),array(0,2,3),array(4,5,6),array(2,2));
	
	print_r(array_column($array,2));
	
	//return 
	
		Array
	(
		[0] => 3
		[1] => 3
		[2] => 6
	)
	
	As you may see the last array has just been ignored .Sometimes it is cool but sometimes you don't want that
	because in a loop you may obtain ugly warning just like offset {number} doesn't exists...It is in this
	situation that you may need to know whether or not an array is suitable for rows and columns selection's process
	and the real keys signature.
	
	
	for a how to use example refer to the file test.php 
	report but via the forum or contact me at leizmo@gmail.com.
  Files folder image Files  
File Role Description
Plain text file array_depth.php Class class source
Accessible without login Plain text file license.txt Lic. license file
Accessible without login Plain text file readme.txt Doc. readme
Accessible without login Plain text file test.php Example example script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:156
This week:0
All time:8,525
This week:395Up