I created this class so that I can easily display arrays while in CLI/Terminal/Console in a table format. Sometimes I need to inspect, and compare values within arrays during migrations or simply when testing a change. I find it extremely helpful to be able to display this data vertically in a table. So the first function (output_comparison) in this class does just that:
In the screenshot, it is evident that this function does a few more things automatically to be able to display the data in a table format:
Boolean values are converted to strings for display only (i.e. true becomes 'true', false becomes 'false')
If an array does not have a value for a particular key, a dash ('-') is used to convey this.
Arrays, and their keys, are handled dynamically. It doesn't matter if the arrays you need to compare don't have a single matching key.
The next function in this class (output_value_comparison) is helpful when you need to compare two array values side-by-side. The display of values is similar to the function above, the difference here is that you have a column which confirms whether the values match or not:
Another feature of this function is an array which is returned that contains all matching and differing values, as well as any values whose comparison could not be determined.
I created this class so that I can easily display arrays while in CLI/Terminal/Console in a table format. Sometimes I need to inspect, and compare values within arrays during migrations or simply when testing a change. I find it extremely helpful to be able to display this data vertically in a table. So the first function (
output_comparison
) in this class does just that: In the screenshot, it is evident that this function does a few more things automatically to be able to display the data in a table format:The next function in this class (
output_value_comparison
) is helpful when you need to compare two array values side-by-side. The display of values is similar to the function above, the difference here is that you have a column which confirms whether the values match or not:Another feature of this function is an array which is returned that contains all matching and differing values, as well as any values whose comparison could not be determined.