I've an associative array titled $rebate_by_product
. This associative array is dynamic in nature means it can be very long or very short depending on data it contains. For your reference I'm showing below the small instance of it which contains three rebate entries.
Array
(
[op] => preview
[id] =>
[form_submitted] => yes
[company_id] => 46
[1] => Array
(
[pack] => 10
[quantity] => 20
[volume] => 30
[units] => 7
[amount] => 40
[rebate_start_date] => 2014-05-01
[rebate_expiry_date] => 2014-05-15
[applicable_states] => Array
(
[0] => 1
[1] => 6
[2] => 11
[3] => 16
[4] => 20
)
[rebate_total_count] => 5000
[products] => Array
(
[1] => 9
[2] => 10
)
)
[2] => Array
(
[pack] => 100
[quantity] => 200
[volume] => 300
[units] => 9
[amount] => 400
[rebate_start_date] => 2014-05-16
[rebate_expiry_date] => 2014-05-31
[applicable_states] => Array
(
[0] => 27
[1] => 32
[2] => 37
[3] => 42
[4] => 47
[5] => 49
)
[rebate_total_count] => 9000
[products] => Array
(
[1] => 11
[2] => 8
)
)
[3] => Array
(
[pack] => 1500
[quantity] => 3000
[volume] => 4500
[units] => 10
[amount] => 6000
[rebate_start_date] => 2014-06-01
[rebate_expiry_date] => 2014-06-07
[applicable_states] => Array
(
[0] => 4
[1] => 13
)
[rebate_total_count] => 7500
[products] => Array
(
[1] => 10
[2] => 11
)
)
[multiselect] => 13
)
You can observe from above array that I'm storing the product id's of products for each rebate entry into array format under key [products]
. Now I don't want repetition of these id's irrespective of the rebate entry to which they belong. That is every rebate entry must have different product ids under key [products]
. To achieve this I think each product id from each rebate entry should be compared with others. May be my approach is wrong. When you come across first match of product ids, error message should display as "Please select different products" and when not a single match found after comparing all the product ids with each other, the success message should display as "All the products are different". How to achieve this in optimum way with minimum loop iterations and by making use of ready made PHP array functions? Thanks for spending some of your time in understanding my issue. If you want any other information regarding the issue I can provide you the same. Any kind of help, suggestions, comments, answers would be highly appreciated. Waiting for your precious replies. Thanks.