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! Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/ 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>"; } } } } } Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489400 Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 Only 672 combinations Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489401 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/ Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489407 Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 I don't know what you mean. Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489409 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? Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489412 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. Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489416 Share on other sites More sharing options...
Barand Posted August 30, 2014 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'); Link to comment https://forums.phpfreaks.com/topic/290757-php-if-while-array-for-all-combination-in-the-post/#findComment-1489417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.