If you notice blade_server_chassis_row = unknown_chassis_row and blade_server_chassis_col = unknown_chassis_col
in the  and  array.
Im trying to compare them to alert my if this happens.
Is this right?
but I don’t think that is the right way to go about it. Will $assetArray only ever have these two elements, $assetArray and $assetArray ? Or will there be other sets of data? if so, how will they be arranged in the array?
Right, so… lets take a step back here, because the title implies a broader picture.
Presumably, you could have many blade servers. Where is this unknown coming from? Have you merged another array? Is this form data you’re handling?
Is the better statement of your problem that you want to compare a single new object against potentially many extant objects in the array? Is the array in a reliable order? Will it always be a given size?
Yes, I need to explain the problem,
I have 5 different types of assets…Blade Servers, Network Cards, Network Modules, Network Standards, and Unknowns.
Any combination of them can belong to a chassis (they would all be given the same chassis_id)
I want tto have some sort of collision detection if they belong to the same row and column in the chassis (chassis_row, chassis_col)I can get all the assets assigned to a chassis into an array,
but dont know how to do the collision detection thing
Ideally, they’d have had the same property names (“chassis_row” instead of “unknown_chassis_row”, etc), but i imagine that ship has sailed at this point. I will, for the moment, assume that we’re stuck with the names we’ve got. If that ship hasnt sailed yet, i’d advise making those changes.
foreach member of the array;
step 1: Identify the current item’s row and col. array_filter the array such that the internal function checks the filter item’s row and col against the foreach item’s row and col; return true if and only if they both match. Catch the result in a variable.
If the result of the array filter is of length greater than 1, there was a collision; the filtered array holds all of the collisions for that item.
As I understand it, this data array is coming from a number of tables or sources that have similar field names containing the source identifier in the field name. IF you had a structured data array which was built with the chassis_row as the primary array key and chassis_col as the secondary array key you could simply count this array[chassis_row][chassis_col] and you would know you have duplicates. As we have a single simple array we will need to build it.
I will go on the assumption that the field called name will be the first field in this array. This will allow you to grab the array keys and use reset() to get the full name of that first compound name field, e.g.
You can then use str_replace() to remove name from these compound names to get the unique $identifier of this array. You can then use this with the field you wish to get the value from.
You can then build the $newdata array placing the chassis_row as the primary key and chassis_col as the secondary array key then count this sub array as you loop through the $newdata and if the count is greater than 1 place this array in a $collision array.