Question about my PHP code

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

Have a look at case http://php.net/manual/en/control-structures.switch.php

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];

 

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.

 

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";