PHP and Algorithmic Thinking for the Complete Beginner: Learn to think like a programmer by mastering PHP and algorithmic thinking.
()
Aristides Bouras
Aristides S. Bouras holds a degree in Computer Engineering from the Technological Educational Institute of Piraeus, and a Dipl. Eng. degree in Electrical and Computer Engineering from the Democritus University of Thrace. He worked as a software developer at a company that specialized in industrial data flow and labelling of products. He has developed many applications such as warehouse managing systems and websites for companies and other organizations. He works as a high school teacher. He mainly teaches computer networks, programming tools for the Internet/intranets, and databases. He has written many books, mainly about algorithmic and computational thinking through Python, C#, C++, Java, PHP, and Visual Basic programming languages.
Read more from Aristides Bouras
Python and Algorithmic Thinking for the Complete Beginner: Learn to think like a programmer by mastering Python programming and algorithmic foundations Rating: 0 out of 5 stars0 ratingsC# and Algorithmic Thinking for the Complete Beginner: Unlock the Power of Programming with C# and Algorithmic Thinking Rating: 0 out of 5 stars0 ratings
Related to PHP and Algorithmic Thinking for the Complete Beginner
Related ebooks
PHP programming Rating: 0 out of 5 stars0 ratingsPHP Programming For Beginners: The Simple Guide to Learning PHP Fast! Rating: 0 out of 5 stars0 ratingsArtificial Intelligence Class 9 Rating: 0 out of 5 stars0 ratingsComputer Programming In C Language Rating: 4 out of 5 stars4/5Excel Formulas & Functions For Dummies Rating: 0 out of 5 stars0 ratingsAlgorithms Unlocked: Mastering Computational Problem Solving Rating: 0 out of 5 stars0 ratingsMastering PHP: Web Development Practices Rating: 0 out of 5 stars0 ratingsGo Programming - From Beginner to Professional: Learn everything you need to build modern software using Go Rating: 0 out of 5 stars0 ratingsC Programming For Dummies Rating: 0 out of 5 stars0 ratingsMastering Algorithm in Python Rating: 0 out of 5 stars0 ratingsAlgorithms Unlocked Rating: 0 out of 5 stars0 ratingsVisual Basic 2005 Demystified Rating: 0 out of 5 stars0 ratingsDesign of a Programmer Rating: 4 out of 5 stars4/5PHP & MYSQL: 200 Solved Exercises and Projects for Practice Rating: 0 out of 5 stars0 ratingsPHP Development Unveiled: A Comprehensive Guide to Mastery and Excellence Rating: 0 out of 5 stars0 ratingsAn Introduction to C & GUI Programming Rating: 0 out of 5 stars0 ratingsPHP and MYSQL: 200 solved exercises and projects for practice: Master dynamic web development Rating: 0 out of 5 stars0 ratingsCoding Interviews Rating: 0 out of 5 stars0 ratingsTouchCode Class 7 Rating: 0 out of 5 stars0 ratingsTeach Yourself VISUALLY Python Rating: 0 out of 5 stars0 ratingsMastering Python: A Comprehensive Crash Course for Beginners Rating: 0 out of 5 stars0 ratingsLearn to Code with C: Program with the world's most popular language on your Raspberry Pi Rating: 5 out of 5 stars5/5C Programming Rating: 0 out of 5 stars0 ratingsThe Art of Code: Exploring the World of Programming Languages Rating: 0 out of 5 stars0 ratingsProgramming Logic Rating: 0 out of 5 stars0 ratingsPython for Absolute Beginners: Learn to Code Fast! Rating: 0 out of 5 stars0 ratingsFoundations of Computing: Essential for Computing Studies, Profession And Entrance Examinations - 5th Edition Rating: 0 out of 5 stars0 ratingsGROKKING ALGORITHM BLUEPRINT: Advanced Guide to Help You Excel Using Grokking Algorithms Rating: 0 out of 5 stars0 ratingsAdvanced Algorithm Mastery: Elevating Python Techniques for Professionals Rating: 0 out of 5 stars0 ratings
Programming For You
SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Ethical Hacking Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5A Slackers Guide to Coding with Python: Ultimate Beginners Guide to Learning Python Quick Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Spies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5COGNITIVE BIASES - A Brief Overview of Over 160 Cognitive Biases: + Bonus Chapter: Algorithmic Bias Rating: 0 out of 5 stars0 ratings
Reviews for PHP and Algorithmic Thinking for the Complete Beginner
0 ratings0 reviews
Book preview
PHP and Algorithmic Thinking for the Complete Beginner - Aristides Bouras
Preface
About the Author
I was born in 1973, and from my early childhood, I discovered a passion for computer programming. At the age of 12, I got my first computer—a Commodore 64, which incorporated a ROM-based version of the BASIC programming language and 64 kilobytes of RAM. It introduced me to the world of programming!
I hold a degree in Computer Engineering from the Technological Educational Institute of Piraeus. Additionally, I earned Dipl. Eng. and Integrated Master's degrees in Electrical and Computer Engineering from the Democritus University of Thrace.
In my previous role as a software developer at a company specializing in industrial data flow and product labeling, my responsibilities included developing software applications for data terminals and PC software for data collection and storage on a Microsoft SQL Server®.
Over the years, I've designed various applications, including warehouse management systems and websites for diverse companies and organizations. Presently, I serve as a computer science teacher in a vocational high school, instructing courses on computer programming, computer networks, programming tools for the Internet/intranets, and databases.
I've authored several books, primarily focusing on algorithmic and computational thinking, utilizing languages such as Python, C#, Java, C++, PHP, and Visual Basic.
Outside of my professional pursuits, I am happily married and have the joy of raising two wonderful children.
Acknowledgments
I would like to thank, with particular gratefulness, my friend and senior editor Victoria (Vicki) Austin for her assistance in copy editing the first edition. Without her, this book might not have reached its full potential. With her patient guidance and valuable and constructive suggestions, she helped me bring this book up to a higher level!
How This Book is Organized
The book you hold in your hands follows the spiral curriculum teaching approach, a method proposed in 1960 by Jerome Bruner, an American psychologist. According to this method, as a subject is being taught, basic ideas are revisited at intervals—at a more sophisticated level each time—until the reader achieves a complete understanding of the subject. First, the reader learns the basic elements without worrying about the details. Later, more details are taught and basic elements are mentioned again and again, eventually being stored in the brain's long-term memory.
According to Jerome Bruner, learning requires the student's active participation, experimentation, exploration, and discovery. This book contains many examples, most of which can be practically performed. This gives the readers the opportunity to get their hands on PHP and become capable of creating their own programs.
Who Should Buy This Book?
Completely updated for the latest version of PHP, this book offers a comprehensive introduction to programming, assuming no prior knowledge of the subject. It is designed for individuals, eager to learn PHP from scratch, providing a strong foundation in Algorithmic Thinking—the fundamental skill every aspiring programmer must acquire. Algorithmic Thinking encompasses more than just writing code; it entails mastering the art of problem-solving through coding.
This edition retains all the popular features of its predecessor while introducing a wealth of new exercises, along with extensive revisions and updates. Furthermore, brand-new chapters offer a practical introduction to working with text files.
Structured for both classroom use and independent study, each chapter is concluded with a set of questions and exercises designed to reinforce your understanding and apply what you've learned. With approximately 250 solved and 480 unsolved exercises, 500 true/false questions, 150 multiple-choice questions, and 200 review questions and crosswords (with solutions and answers available online), this book is ideal for:
► Novices or intermediate-level programmers pursuing self-study
► High school students
► First-years college or university students
► Educators
► Professors
► Anyone who wants to start learning or teaching computer programming using the best practices and techniques
Conventions Used in This Book
Following are some explanations on the conventions used in this book. Conventions
refer to the standard ways in which certain parts of the text are displayed.
PHP Statements
This book uses plenty of examples written in PHP language. PHP statements are shown in a typeface that looks like this.
This is a PHP statement
Keywords, Variables, Functions, and Arguments Within the Text of a Paragraph
Keywords, variables, functions (subprograms), and arguments are sometimes shown within the text of a paragraph. When they are, the special text is shown in a typeface different from that of the rest of the paragraph. For instance, $firstName = 5 is an example of a PHP statement within the paragraph text.
Words in Italics
You may notice that some of the special text is also displayed in italics. In this book, italicized words are general types that must be replaced with the specific name appropriate for your data. For example, the general form of a PHP statement may be presented as
function name(arg1, arg2)
In order to complete the statement, the keywords name, arg1, and arg2 must be replaced with something meaningful. When you use this statement in your code, you might use it in the following form
function displayRectangle($width, $height)
Three dots (…): an Ellipsis
In the general form of a statement you may also notice three dots ( … ), also known as an ellipsis
, following a list in an example. They are not part of the statement. An ellipsis indicates that you can have as many items in the list as you want. For example, the ellipsis in the general form of the statement
displayMessages(arg1, arg2, … );
indicates that the list may contain more than two arguments. When you use this statement in your code, your statement might be something like this.
displayMessages($message1, "Hello, $message2,
Hi!");
Square Brackets in Italics
The general form of some statements or functions (subprograms) may contain square brackets
[ ] in italics, which indicate that the enclosed section is optional. For example, the general form of the statement
substr(subject, beginIndex [, length])
indicates that the section [, length] can be omitted.
For example, the following two statements may produce different results but they are both syntactically correct.
$a = substr($s, 3);
$b = substr($s, 3, 9);
The Dark Header
Most of this book's examples are shown in a typeface that looks like this.
file_29.2-3
$a = 1;
$b = 2;
echo $a + $b;
?>
The header file_29.2-3 on top indicates the filename that you must open to test the code. All the examples that contain this header can be downloaded free of charge from my website.
Notices
Very often this book uses notices to help you better understand the meaning of a concept. Notices look like this.
This typeface designates a note.
Something Already Known or Something to Remember
Very often this book can help you recall something you have already learned (probably in a previous section or chapter). Other times, it will draw your attention to something you should memorize. Reminders look like this.
This typeface designates something to recall or something that you should memorize.
How to Report Errata
Although I have taken great care to ensure the accuracy of the content in this book, mistakes can still occur. If you come across any errors, either in the text or the code, I highly encourage you to send me a report. By doing so, you'll not only assist in saving other readers from potential confusion and frustration but also contribute to enhancing the quality of the next release. If you discover any errors, please report them by visiting one of the following addresses:
https://tinyurl.com/28nwh2nf
https://www.bouraspage.com/report-errata
.
Once I verify your reported error(s), your submission will be accepted. The errata will then be uploaded to my website and added to any existing list of corrections.
Where to Download Material About this Book
Material about this book, such as:
► a list of verified errata (if any);
► the Solutions Companion, providing answers to all review questions and solutions to exercises; and
► all of this book's examples that have a header like this file_29.2-3 on top
can be downloaded free of charge from the following addresses:
https://tinyurl.com/5fvbd8a7
https://www.bouraspage.com/books/php-and-algorithmic-thinking-for-the-complete-beginner-third-edition
.
If you Like this Book
If you find this book valuable, please consider visiting the web store where you purchased it, as well as goodreads.com, to show your appreciation by writing a positive review and awarding as many stars as you think appropriate. By doing so, you will motivate me to keep writing and, of course, you'll be assisting other readers in discovering my work.
Part I
Introductory Knowledge
Chapter 1
How a Computer Works
1.1 Introduction
In today's society, almost every task requires the use of a computer. In schools, students use computers to search the Internet and to send emails. At work, people use them to make presentations, to analyze data, and to communicate with customers. At home, people use computers to play games, to connect to social networks and to chat with other people all over the world. Of course, don't forget smartphones such as iPhones. They are computers as well!
Computers can perform so many different tasks because of their ability to be programmed. In other words, a computer can perform any job that a program tells it to. A program is a set of statements (often called instructions or commands) that a computer follows in order to perform a specific task.
Programs are essential to a computer, because without them a computer is a dummy machine that can do nothing at all. It is the program that actually tells the computer what to do and when to do it. On the other hand, the programmer or the software developer is the person who designs, creates, and often tests computer programs.
This book introduces you to the basic concepts of computer programming using the PHP language.
1.2 What is Hardware?
The term hardware refers to all devices or components that make up a computer. If you have ever opened the case of a computer or a laptop you have probably seen many of its components, such as the microprocessor (CPU), the memory, and the hard disk. A computer is not a device but a system of devices that all work together. The basic components of a typical computer system are discussed here.
► The Central Processing Unit (CPU)
This is the part of a computer that actually performs all the tasks defined in a program (basic arithmetic, logical, and input/output operations).
► Main Memory (RAM – Random Access Memory)
This is the area where the computer holds the program (while it is being executed/run) as well as the data that the program is working with. All programs and data stored in this type of memory are lost when you shut down your computer or you unplug it from the wall outlet.
► Main Memory (ROM – Read Only Memory)
ROM or Read Only Memory is a special type of memory which can only be read by the computer (but cannot be changed). All programs and data stored in this type of memory are not lost when the computer is switched off. ROM usually contains manufacturer's instructions as well as a program called the bootstrap loader whose function is to start the operation of computer system once the power is turned on.
► Secondary Storage Devices
This is usually the hard disk or the SSD (Solid State Drive), and sometimes (but more rarely) the CD/DVD drive. In contrast to main memory (RAM), this type of memory can hold data for a longer period of time, even if there is no power to the computer. However, programs stored in this memory cannot be directly executed. They must be transferred to a much faster memory; that is, the main memory.
► Input Devices
Input devices are all those devices that collect data from the outside world and enter them into the computer for further processing. Keyboards, mice, and microphones are all input devices.
► Output Devices
Output devices are all those devices that output data to the outside world. Monitors (screens) and printers are output devices.
1.3 What is Software?
Everything that a computer does is controlled by software. There are two categories of software: system software and application software.
► System software is the program that controls and manages the basic operations of a computer. For example, system software controls the computer's internal operations. It manages all devices that are connected to it, and it saves data, loads data, and allows other programs to be executed. The three main types of system software are:
► the operating system . Windows, Linux, macOS, Android, and iOS are all examples of operating systems.
► the utility software . This type of software is usually installed with the operating system. It is used to make the computer run as efficiently as possible. Antivirus utilities and backup utilities are considered utility software.
► the device driver software . A device driver controls a device that is attached to your computer, such as a mouse or a graphic card. A device driver is a program that acts like a translator. It translates the instructions of the operating system to instructions that a device can actually understand.
► Application software refers to all the other programs that you use for your everyday tasks, such as browsers, word processors, notepads, games, and many more.
1.4 How a Computer Executes (Runs) a Program
When you turn on your computer, the main memory (RAM) is completely empty. The first thing the computer needs to do is to transfer the operating system from the hard disk to the main memory.
After the operating system is loaded to main memory, you can execute (run) any program (application software) you like. This is usually done by clicking, double clicking, or tapping the program's corresponding icon. For example, let's say you click on the icon of your favorite word processor. This action orders your computer to copy (or load) the word processing program from your hard disk to the main memory (RAM) so the CPU can execute it.
Programs are stored on secondary storage devices such as hard disks. When you install a program on your computer, the program is copied to your hard disk. Then, when you execute a program, the program is copied (loaded) from your hard disk to the main memory (RAM), and that copy of the program is executed.
The terms run
and execute
are synonymous and can be used interchangeably.
1.5 Compilers and Interpreters
Computers can execute programs that are written in a strictly defined computer language. You cannot write a program using a natural language such as English or Greek, because your computer won't understand you!
But what does a computer actually understand? A computer can understand a specific low-level language called the machine language. In a machine language all statements (or commands) are made up of zeros and ones. The following is an example of a program written in a machine language, that calculates the sum of two numbers.
0010 0001 0000 0100
0001 0001 0000 0101
0011 0001 0000 0110
0111 0000 0000 0001
Shocked? Don't worry, you are not going to write programs this way. Hopefully, no one writes computer programs this way anymore. Nowadays, all programmers write their programs in a high-level language and then they use a special program to translate them into a machine language.
A high-level language is one that is not limited to a particular type of computer.
There are two types of programs that programmers use to perform translation: compilers and interpreters.
A compiler is a program that translates statements written in a high-level language into a separate machine language program. You can then execute the machine language program any time you wish. After the translation, there is no need to run the compiler again unless you make changes in the high-level language program.
An interpreter is a program that simultaneously translates and executes the statements written in a high-level language. As the interpreter reads each individual statement in the high-level language program, it translates it into a machine language code and then directly executes it. This process is repeated for every statement in the program.
1.6 What is Source Code?
The statements (often called instructions or commands) that the programmer writes in a high-level language are called source code or simply code. The programmer first types the source code into a program known as a code editor, and then uses either a compiler to translate it into a machine language program, or an interpreter to translate and execute it at the same time.
Source code can even be written in a simple text editor!
1.7 Review Questions: True/False
Choose true or false for each of the following statements.
1) Modern computers can perform so many different tasks because of their ability to be programmed.
2) A computer can operate without a program.
3) A hard disk is an example of hardware.
4) Data can be stored in main memory (RAM) for a long period of time, even if there is no power to the computer.
5) Data is stored in main memory (RAM), but programs are not.
6) Speakers are an example of an output device.
7) Windows and Linux are examples of software.
8) A device driver is an example of hardware.
9) A media player is an example of system software.
10) When you turn on your computer, the main memory (RAM) already contains the operating system.
11) When you open your word processing application, it is actually copied from a secondary storage device to the main memory (RAM).
12) In a machine language, all statements (commands) are a sequence of zeros and ones.
13) Nowadays, a computer cannot understand zeros and ones.
14) Nowadays, software is written in a language composed of ones and zeros.
15) Software refers to the physical components of a computer.
16) The compiler and the interpreter are software.
17) The compiler translates source code to an executable file.
18) The interpreter creates a machine language program.
19) Considering that a program might be executed multiple times, after it has been translated through interpretation and executed once, the need for the interpreter becomes obsolete.
20) Source code can be written using a simple text editor.
21) Source code can be executed by a computer without compilation or interpretation.
22) A program written in machine language requires compilation (translation).
23) A compiler translates a program written in a high-level language.
1.8 Review Questions: Multiple Choice
Select the correct answer for each of the following statements.
1) Which of the following is not computer hardware?
a) a hard disk
b) a DVD disc
c) a sound card
d) the main memory (RAM)
2) Which of the following is not a secondary storage device?
a) a DVD reader/writer device
b) a Solid State Drive (SSD)
c) a USB flash drive
d) RAM
3) Which one of the following operations can not be performed by the CPU?
a) Transfer data to the main memory (RAM).
b) Transfer data from the main memory (RAM).
c) Perform arithmetic operations.
d) Surgical operations.
4) A touch screen is
a) an input device.
b) an output device.
c) both of the above
5) Which of the following is not software?
a) Windows
b) Linux
c) iOS
d) a video game
e) a web browser
f) All of the above are software.
6) Which of the following statements is correct?
a) Programs are stored on the hard disk.
b) Programs are stored on USB flash drives (USB sticks).
c) Programs are stored in main memory (RAM).
d) All of the above are correct.
7) Which of the following statements is correct?
a) Programs are executed directly from the hard disk.
b) Programs are executed directly from a DVD disc.
c) Programs are executed directly from the main memory (RAM).
d) All of the above are correct.
e) None of the above is correct.
8) Programmers can not write computer programs in
a) machine language.
b) natural language such as English, Greek, and so on.
c) PHP.
9) A compiler translates
a) a program written in machine language into a high-level language program.
b) a program written in a natural language (English, Greek etc.) into a machine language program.
c) a program written in high-level computer language into a machine language program.
d) none of the above
e) all of the above
10) Machine language is
a) a language that machines use to communicate with each other.
b) a language made up of numerical instructions that is used directly by a computer.
c) a language that uses English words for operations.
11) In a program written in high-level computer language, if two identical statements are one after the other, the interpreter
a) translates the first one and executes it, then it translates the second one and executes it.
b) translates the first one, then translates the second one, and then executes them both.
c) translates only the first one (since they are identical) and then executes it twice.
Chapter 2
PHP and Integrated Development Environments
2.1 What is PHP?
PHP is a widely used open source server-side scripting language that is especially suited for web development and can be combined with HTML. Server side
means that scripts written in PHP can be executed by a web server, such as Apache or IIS, with a PHP module installed.
While the acronym PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor.
2.2 What is the Difference Between a Script and a Program?
Technically speaking, a script is interpreted whereas a program is compiled, but this is actually not their major difference. There is another more important difference between them!
The main purpose of a script written in a scripting language such as PHP, JavaScript, or VBA (Visual Basic for Applications) is to control another application. So you can say that, in some ways , PHP controls the web server, JavaScript controls the web browser, and VBA controls a Microsoft® Office application such as MS Word or MS Excel.
On the other hand, a program written in a programming language such as Java, C++, or C# (to name a few) executes independently of any other application. A program is executed as stand-alone any time the user wishes without the need of a hosting application.
Macros of Microsoft Office are scripts written in VBA. Their purpose is to automate certain functions within Microsoft Office.
A lot of people think that JavaScript is a simplified version of Java but in fact the similarity of the names is just a coincidence.
A script cannot be executed as stand-alone. It requires a hosting application in order to execute.
2.3 Why You Should Learn PHP
PHP is what is known as a high-level
computer language. It is a powerful server-side scripting language available on even the most affordable shared hosting servers. Some of the biggest websites on the Internet, including Facebook and Wikipedia, are built with PHP. Furthermore, the most popular Content Management Systems (CMS) such are Drupal, WordPress, and Joomla are written in PHP.
PHP's coding style is similar to C language. It is quite easy to understand and highly efficient on multiple platforms such as Windows, Linux, and Unix. PHP is a flexible and powerful language, making it well-suited for developing dynamic web pages.
One of PHP's capabilities is the ability to interact with the file system of a computer. PHP can create files, write in files, or read the contents from files. It can also create directories (folders), copy files, delete files, rename files, or even change file attributes. Although PHP was originally designed to work in web pages, its ability to perform almost any task related to the file system makes it suitable even for system administration tasks. For example, you can create a PHP script to back up your files or a script that processes text files by reformatting their contents.
Moreover, PHP can execute system commands or any other program installed on your system. Thus, programs written and compiled in C, C++, Perl, or any other computer language can be executed from PHP and PHP can make use of their output. This enables you to add functionality to your scripts without spending time rewriting your old programs.
With a huge community of developers worldwide, PHP enables efficient development of many exciting web applications, websites, extensions and themes for Drupal, WordPress and Joomla, to name a few. This huge availability of PHP programmers is a major reason why organizations choose PHP for new development over any other programming/scripting language. This is also a very good reason why you should actually learn PHP!
2.4 How PHP Works
Computers do not understand natural languages such as English or Greek, so you need a computer language such as PHP to communicate with them. PHP is a very powerful high-level computer language. The PHP interpreter converts PHP code into a language that computers can understand, known as machine language
.
The PHP interpreter comes in two flavors—the one that can be used with websites, and the other, which you can run from the command line (CLI: Command Line Interface). The latter is the one that this book actually uses.
To write and execute PHP scripts, you need to install PHP CLI, XDEBUG and an Integrated Development Environment (IDE). The IDE is necessary for writing PHP scripts, while PHP CLI and XDEBUG are required for executing and debugging them.
2.5 Integrated Development Environments
An Integrated Development Environment, or IDE, is a type of software that includes all the basic tools programmers need to write and test programs. An IDE typically contains a source code editor and integrates tools such as a compiler or an interpreter, along with a debugger. Visual Studio Code is an example of IDE that let programmers write, execute and debug their source code.
A debugger
is a tool that helps programmers to find and correct many of their mistakes.
2.6 Visual Studio
Microsoft Visual Studio is an Integrated Development Environment (IDE) that provides a great set of tools for many programming (or scripting) languages (via extensions installed separately) and lets you easily create applications for Android, iOS, macOS, Windows, and the cloud, as well as websites, web applications, and web services.
Visual Studio is much more than a text editor. It can indent lines, match words and brackets, and highlight source code that is written incorrectly. It also provides automatic code (IntelliSense®), which means that as you type, it displays a list of possible completions. The IDE also provides hints to help you analyze your code and find any potential problems. It even suggests some simple solutions to fix those problems. You can use the Visual Studio not only to write but also to execute and debug your programs directly from the IDE.
Visual Studio has a large community of users all around the world and this is why it comes in so many different flavors. Specifically, in Microsoft's download page you can download:
► Visual Studio (Community, Professional, or Enterprise), which runs on Windows
► Visual Studio for Mac , which runs on macOS
► Visual Studio Code , which runs on Windows, macOS, and Linux
In the next chapter (Chapter 3), you will find links guiding you to instructions on how to install and configure whatever is necessary on your computer, such as the PHP CLI interpreter, XDEBUG and Visual Studio Code, on either Windows or Linux. Then, in Chapter 9, you will discover guidance on using Visual Studio Code to write, execute and debug PHP scripts. These instructions are available on my website. Additionally, you will find numerous tips and tricks there that will be valuable in your first steps as a budding programmer!
Chapter 3
Software Packages to Install
3.1 What to Install
For the purposes of this book, you need to install PHP CLI, XDEBUG and an Integrated Development Environment (IDE) such as Visual Studio Code on your computer.
All the instructions you need regarding how to set up PHP CLI, XDEBUG and Visual Studio Code, on either Windows or Linux are maintained on my website at the following addresses. This gives me the flexibility to review them frequently and keep them up-to-date.
https://tinyurl.com/5n7xym8f
https://www.bouraspage.com/php-setup-write-execute-debug
.
If you find any inconsistencies, please let me know, and I will update the instructions as soon as possible. To report issues, visit one of the following addresses:
https://tinyurl.com/28nwh2nf
https://www.bouraspage.com/report-errata
.
Currently, all you need is to install PHP CLI, XDEBUG and Visual Studio Code. Instructions on my website regarding how to write, execute, and debug a PHP script are unnecessary at this stage. You will require these instructions when you reach Chapter 9.
Review in Introductory Knowledge
Review Crossword Puzzles
1) Solve the following crossword puzzle.
Across
1) Statements or commands.
3) Windows is such a system.
4) A computer component.
6) A category of software.
8) An input device.
11) It's the person who designs computer programs.
14) An output device.
15) Antivirus is such a software.
16) In today's society, almost every task requires the use of this device.
17) A computer component.
18) All these devices make up a computer.
Down
2) These devices are also computers.
5) Computers can perform so many different tasks because of their ability to be _____________.
7) Special memory that can only be read.
9) A secondary storage device.
10) A browser is this type of software.
12) An input device.
13) An operating system.
2) Solve the following crossword puzzle.
Across
2) The CPU performs one of these basic operations.
4) A scripting language.
6) A set of statements.
10) A low-level language.
12) This software controls a device that is attached to your computer.
13) The statements that a programmer writes to solve a problem.
Down
1) A category of programming language.
3) A program that simultaneously translates and executes the statements written in a high-level language.
5) A program that translates statements written in a high-level language into a separate machine language program.
7) In a machine language all statements are made up of zeros and _____.
8) All data stored in this type of memory are lost when you shut down your computer.
9) Run a program.
11) Visual Studio is such a software.
3) Solve the following crossword puzzle.
Across
1) PHP can execute _________ commands.
4) Scripts written in VBA.
6) It performs logical operations.
7) A scripting language that can control Microsoft Word.
8) It displays data to the user.
9) One of PHP's capabilities is the ability to interact with the _____ system of a computer.
Down
2) An input device.
3) A script requires a __________ application in order to execute.
5) PHP is suitable for developing ________ web pages.
Review Questions
Answer the following questions.
1) What is hardware?
2) List the five basic components of a typical computer system.
3) What does the bootstrap loader
program do?
4) Which part of the computer actually executes the programs?
5) Which part of the computer holds the program and its data while the program is running?
6) Which part of the computer holds data for a long period of time, even when there is no power to the computer?
7) How do you call the device that collects data from the outside world and enters them into the computer?
8) List some examples of input devices.
9) How do you call the device that outputs data from the computer to the outside