Friday, January 9, 2015

PHP

PHP

March 2014. Time marches on while you’re taking a college course. I've been spending about at least 24 hours a week learning and programming in C++.

My C++ programs include about 365 or more lines of code, including the comments and blank lines, starting from scratch, of course. And since we are now using header files and implementation files, instead of just one program file, the lines of code averages about 500 lines per application.

We were assigned one large program every other week. The college catalog was not kidding when it said the course was about writing large programs.

By the end of this month, we have already studied inheritance, overloading operators, and recursion. The next two months are about exception handling, about the most interesting part of C++, pointers, about dynamic structures, generic types, and lastly, linked lists.

About this time also, the only other programming tutor in my college left for better pasture. He was finally hired by the local company he was writing PHP codes for. So, there and there, I intended to learn programming in PHP also.

PHP is a server side language, so it can only be properly executed in a server computer. Here is a sample PHP code I wrote and run. The HTML code is stored in the server, not on the client computer. It can be executed in the server and the result is passed to the client’s browser to display to the user.

<!DOCTYPE html>
<html>
<body>
<?php
#declare and initialize global variable.
$year = 2015;
function askYear($year) {
    echo "<p>Is this the year $year?</p>";
}
askYear($year);
if ($year ==  2015) {
     echo "<p>It sure is!</p>";
}
else {
     echo "<p>It sure ain't!</p>";
}
?>
</body>
</html>

CYK:
How do you declare a variable named "student" in PHP?
What kind of statement is used for two-branch structure?
What keyword does a "switch" keyword always look for?

Happy computing!

John Sindayen

No comments:

Post a Comment