How it works...

The main idea here is the use of foreach. When using the Foreach loop construct, you refer to each element with a variable; variables are not identified with an index in this case. For every iteration, in our case, $Guest picks one value from $Guests, in sequence, so that the current element can be referred using $Guest.

The seat numbers have a pattern: an alpha row identifier, followed by a hyphen, followed by the numeric seat identifier.

The seat number is a string. We split it at -, pick the first element in the resultant array, convert it to uppercase (in case it already isn't), convert this letter to a character, and then, use the [byte] cast operator to find its ASCII identifier. And yes, we subtract 64 from it (so A becomes 1).

To be able to use the number with switch–case without errors, we convert the number back to a string. We make the number friendly for use in a sentence. We take the second (numeric) part of the array to see which side of the aisle the seat is located on. We combine all these to get the resultant greeting-and-guidance strings, which are displayed after a delay of one second each.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.172.146