Jim R Posted April 26, 2018 Share Posted April 26, 2018 I'm passing variables passed through the URL for year and team. For example: $year = 19, $team = 2 I'm joining those variables and creating a value which will correspond to team's page on a site. $number = 192 The question is how do I set up my array to use that value 192 to make $calendar = 2019roots ? $year = $_GET['&year']; $team = $_GET['&team']; $number = $year.$team; echo $number; $calendar = array ( '192' =>'2019roots', '212' =>'2021roots', '191' =>'2019grind', '201' =>'2020grind', '211' =>'2021grind', '221' =>'2022grind', '231' =>'2023grind' ); I'm going to use that value to call up the corresponding calendar based on which team's page the User is viewing. (I suppose I could create a series of if/else statements, but I'd rather learn how to do this. I've tried searching for examples, but I'm not even sure how to concisely query the search.) Quote Link to comment Share on other sites More sharing options...
Jim R Posted April 26, 2018 Author Share Posted April 26, 2018 I might've made the above too complicated, which is to say I was way off. I've changed the code, but now it just prints 'array'. $year = $_GET['&year']; $team = $_GET['&team']; $calendar = $year.$team; $calendar = array ( '192' =>'2019roots', '212' =>'2021roots', '191' =>'2019grind', '201' =>'2020grind', '211' =>'2021grind', '221' =>'2022grind', '231' =>'2023grind' ); echo $calendar; Quote Link to comment Share on other sites More sharing options...
Solution Jim R Posted April 27, 2018 Author Solution Share Posted April 27, 2018 This works. $year = $_GET['&year']; $team = $_GET['&team']; $number = $year.$team; // echo $number; $calendars = array ( '192' =>'2019roots', '212' =>'2021roots', '191' =>'2019grind', '201' =>'2020grind', '211' =>'2021grind', '221' =>'2022grind', '231' =>'2023grind' ); echo $calendars [$number]; echo do_shortcode( '[calendarizeit calendar="'. $calendars [$number] .'"]' ); Quote Link to comment Share on other sites More sharing options...
Barand Posted April 27, 2018 Share Posted April 27, 2018 An alernative would be to keep the $year and $team separate $cal_arr = [ 1 => [ 19 => '2019grind' , 20 => '2020grind' , 21 => '2021grind' , 22 => '2021grind' , 23 => '2021grind' ] , 2 => [ 19 => '2019roots' , 21 => '2021roots' ] ]; $calendar = $cal_arr[$team][$year]; Which could be further simplified to $team_cal = [ 1 => 'grind', 2 => 'roots' ]; $calendar = '20' . $year . $team_cal[$team]; 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.