php - Finding closest aggregated value using Knapsack or foreach -


i looking simplest solution problem time efficient on server.

i have value have approach close possible, minimum of items being summed together.

i have values stored in multidimensional array of values, smaller value looking for.

solution nr.1 sort, send through foreach sentance , first , last value , sum them , if big, use next biggest value, if small use next smallest.

or try sort of knapsack implementation me least amount of items used.

any suggestions on better? or missing solution?

    $example = array(     [0]=>([val]=>'1684'),     [1]=>([val]=>'2759'),     [2]=>([val]=>'3997'),     [3]=>([val]=>'8543'),     [4]=>([val]=>'9534'),     [5]=>([val]=>'957'),); 

this example of array, want value closest 13000. time efficient path take if had betweek 10 , 250 results per array


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -