emmontenegro Posted August 30, 2014 Share Posted August 30, 2014 $space = array('3x3', '3x3_6x6', '3x3_6x6', '6x6_10x10', '10x10_20x20', '20x20_40x40', 'above_40x40'); $location = array('schools', 'malls', 'publicParks_outdoorAreas','residentialCompounds'); $ageGroup = array('6_12yo','13_18yo'); $duration = array('20mins', '1hour', '4hours','4_6hours'); $footfall = array('100', '100_500', 'above_500'); The above codes are the arrays for my system What I need is a simplified algorithm for this output: - 3x3, schools, 6-12 y/o, 20mins, 100 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 20mins, 100-500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 20mins, Above 500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 1 hour, 100 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 1 hour, 100-500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 1 hour, Above 500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4 hour, 100 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4 hour, 100-500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4 hour, Above 500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4-6 hour, 100 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4-6 hour, 100-500 = SOMETHING HERE - 3x3, schools, 6-12 y/o, 4-6 hour, Above 500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 20mins, 100 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 20mins, 100-500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 20mins, Above 500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 1 hour, 100 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 1 hour, 100-500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 1 hour, Above 500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4 hour, 100 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4 hour, 100-500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4 hour, Above 500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4-6 hour, 100 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4-6 hour, 100-500 = SOMETHING HERE - 3x3, schools, 13-18 y/o, 4-6 hour, Above 500 = SOMETHING HERE - 3x3_6x6...etc... I tried this code, but I'm lost: if (in_array($post_space, $space) && in_array($post_location, $location) && in_array($post_ageGroup, $ageGroup) && in_array($post_duration, $duration) && in_array($post_footfall, $footfall)) { } I want every combination to consider. Please help. Thanks! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 foreach($space as $s) { foreach($location as $l) { foreach($ageGroup as $a) { foreach($duration as $d) { foreach($footfall as $f) { echo "$s, $l, $a, $d, $f = SOMETHING HERE<br>"; } } } } } Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 Only 672 combinations Quote Link to comment Share on other sites More sharing options...
emmontenegro Posted August 30, 2014 Author Share Posted August 30, 2014 Hi, Thank you so much for that. How about the if statement inside? Because I need to write different string for each combination Thanks again! You rock! \m/ Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 I don't know what you mean. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 30, 2014 Share Posted August 30, 2014 Is this some kind of school project that you come here with no code to show at all and only want someone to write you a solution? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 30, 2014 Share Posted August 30, 2014 Use CroNiX's code to generate a form so you can add comments and save them to, say, a CSV file. To edit, reload the file, change and re-save. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted August 30, 2014 Solution Share Posted August 30, 2014 Only 672 combinations No, only 576. One of the "space" array values is duplicated $space = array('3x3', '3x3_6x6', '3x3_6x6', '6x6_10x10', '10x10_20x20', '20x20_40x40', 'above_40x40'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.