Jump to content

Question about my PHP code


Miggel

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...