While this is not really an error, extra data that is not used should not be included in any output as it will only add to the extra bytes.

When you look at your JSON output, you realized the column names and values also have extra index column numbers and the associated values included.

To remove this, simply add an option in the PDO when you instantiate a database connection in PHP like this:

That should fix the problem. When you use json_encode(), there will be no more duplicate values with the corresponding column index number as key.

This is beyond my intellect since I am just totally bad with Math so the only thing left for me to do was the scour the Internet to try and find if anyone posted a solution to getting a list of subset from a given set that sum up to a specific value.

I wanted it to be a simple static method but out of the possible solutions that I came across with, only the class made by user rolfl in the Code Review StackExchange website met my needs.

This class made it possible for me to use the class and loop through each set and see if any of those have numbers that sum up to the specific value that I want.

Here is the class.

To use the class. Do it like this:

The example looks for subsets of a given set that sum up to the value 15. The dummy variable is an ArrayList of type Integer.

Then, if any subsets are found within the set, the totalsubset variable will have a value of more than 0.

You can modify the class to suit your requirements like getting the list of subsets by modifying the code in the print() method.

This is the best 1 liner answer I found in the Internet to check if an array’s item or value or however you may call it exists in another array.

Using the function array_intersect(), you can achieve this. User lorenzo-s from Stack Overflow gave this 1 liner code that did the trick.

Do note that array_intersect() is case sensitive.

Related Posts Plugin for WordPress, Blogger...