Miggel Posted November 10, 2017 Report Share Posted November 10, 2017 Hi community I have a question. Is there a way to simplify or improve this code? I would like, if there is no information to the airport, a text like example: no gate info available.PS I'm a beginner with php <?php $zurich[] = "Terminal 1 Dock A"; $zurich[] = "Terminal 2 Dock B"; $zurich[] = "Terminal 3 Dock E"; $zurich[] = "Dock D"; $zufallsIndex = rand(0,sizeof($zurich)-1); if($info->destination[0]->icao_code == 'LSZH') echo $zurich[$zufallsIndex]; elseif($info->destination[0]->icao_code == 'BKPR') echo "Stands 201 - 203"; elseif($info->destination[0]->icao_code == 'GCFV') echo "Stands 18 - 22"; elseif($info->destination[0]->icao_code == 'GCLP') echo "Stands T02 - T07"; elseif($info->destination[0]->icao_code == 'GCRR') echo "Stands T01 - T07"; elseif($info->destination[0]->icao_code == 'GCTS') echo "Stands F02 - F08"; elseif($info->destination[0]->icao_code == 'HEGN') echo "Stands 69 - 74"; elseif($info->destination[0]->icao_code == 'HESH') echo "Stands 26 - 33"; elseif($info->destination[0]->icao_code == 'KTPA') echo "Stands 85 - 89"; elseif($info->destination[0]->icao_code == 'LBWN') echo "Stands 15 - 19"; elseif($info->destination[0]->icao_code == 'LCLK') echo "Stands 22 - 26"; elseif($info->destination[0]->icao_code == 'LICC') echo "Stands 327 - 331"; elseif($info->destination[0]->icao_code == 'LPMA') echo "Stands A5 - A10"; elseif($info->destination[0]->icao_code == 'MUHA') echo "Stands 10 - 11"; elseif($info->destination[0]->icao_code == 'LEPA') echo "Stands 40 - 63"; elseif($info->destination[0]->icao_code == 'LIEO') echo "Gates 01 - 05"; elseif($info->destination[0]->icao_code == 'LEIB') echo "Stands 27P - 31P"; ?> greez Michi Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 10, 2017 Members Report Share Posted November 10, 2017 Have a look at case http://php.net/manual/en/control-structures.switch.php Quote Link to comment Share on other sites More sharing options...
magicflyer Posted November 10, 2017 Report Share Posted November 10, 2017 Still o(N) but cleaner to read. <?php $zurich = ['Terminal 1 Dock A', 'Terminal 2 Dock B', 'Terminal 3 Dock E']; $parkings = [ 'LSZH' => $zurich[array_rand($zurich)], 'BKPR' => 'Stands 201 - 203', 'GCFV' => 'Stands 18 - 22', 'GCLP' => 'Stands T02 - T07', 'GCRR' => 'Stands T01 - T07', 'GCTS' => 'Stands F02 - F08', 'HEGN' => 'Stands 69 - 74', 'HESH' => 'Stands 26 - 33', 'KTPA' => 'Stands 85 - 89', 'LBWN' => 'Stands 15 - 19', 'LCLK' => 'Stands 22 - 26', 'LICC' => 'Stands 327 - 331', 'LPMA' => 'Stands A5 - A10', 'MUHA' => 'Stands 10 - 11', 'LEPA' => 'Stands 40 - 63', 'LIEO' => 'Gates 01 - 05', 'LEIB' => 'Stands 27P - 31P' ]; echo $parkings[$info->destination[0]->icao_code]; Quote Link to comment Share on other sites More sharing options...
Miggel Posted November 10, 2017 Author Report Share Posted November 10, 2017 (edited) wow thank you, but dosent work And what do I do if there is no standard gate, so no ICAO code? . Can I generate something where then is: No information available. Edited November 10, 2017 by MichiGobeli Quote Link to comment Share on other sites More sharing options...
magicflyer Posted November 11, 2017 Report Share Posted November 11, 2017 (edited) Works just fine. Make sure you have the PHP closing tags correctly....https://ideone.com/bQqklA And for your second question...you can use. Catch is I think this code will only work in PHP 7: echo $parkings[$info->destination[0]->icao_code] ?? "Some message that it does not exist"; Edited November 11, 2017 by magicflyer 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.