PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

PHP · Theory

Code

← All stacks

Theory

5/352

Code

PHP is a language for web pages that run on the server. The browser asks for result.php. The server runs PHP, talks to a database if needed, and sends HTML back. You do not write PHP for the browser to compile like Java. You write a .php file the server executes.

Smallest file: <?php echo 'Hello PHP'; ?> Save as hello.php under the web root (htdocs in XAMPP). Open http://localhost/hello.php. If you see Hello PHP, install is working. If you see the source, Apache/PHP is not running or you opened the file as file://.

Variables start with $. $marks = 72; echo $marks; Strings in quotes. Every statement ends with ; . Forms send data to PHP as $_GET or $_POST. That is how login and result pages work.

Trap: calling PHP a database. MySQL is the database. PHP is the language that talks to it. Trap: using the old mysql_ functions — use mysqli or PDO with prepared statements.

Diagram
Browser
    │  GET /hello.php
    ▼
  PHP on the server
    │  echo
    ▼
  HTML back to browser
Exam tip

Server language. echo Hello. $marks. PHP is not the database.

Example

<?php
// Code
$scores = [80, 90, 70];
$avg = array_sum($scores) / count($scores);
echo "avg=" . number_format($avg, 1) . "\n";
foreach ($scores as $s) {
  if ($s >= 80) echo "high: $s\n";
}

Code: scores array, print avg, then high marks. Say the output.

Short notes

  • DefPHP runs on the server and prints HTML (or JSON).
  • Rule<?php … ?> echo, $variables, semicolon.
  • Usecollege portals, WordPress, APIs.
  • TrapPHP ≠ MySQL. Don’t use mysql_ .

Questions

1

What is PHP?

2

Smallest example?

5 / 352

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.