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

PHP · Theory

Variable

← All stacks

Theory

9/352

Variable

Don’t start Variable with jargon. Start with $marks = 72. That is the whole point.

Variable on the board — $name = 'Asha';. Then say what $marks = 72 looks like after.

Variable exists so Dev can keep $marks = 72 correct in a result script.

Use Variable when $marks = 72 must stay clear. If a simpler PHP step works, use that instead.

Variable trap — using marks without $. Dev loses marks for that every viva.

After Variable, Dev should still remember using marks without $.

Viva for Variable — what it is → $name = 'Asha'; → the mistake (using marks without $).

Exam tip

Board: $marks = 72. Dry-run Variable. Name the trap: using marks without $.

Example

<?php
// Variable
$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";
}

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

Short notes

  • DefVariable — Dev uses it for $marks = 72 in a result script.
  • RuleVariable → $name = 'Asha';.
  • RememberVariable + Apache/Nginx (a result script).
  • UseVariable in a result script ($marks = 72).
  • TrapVariable — using marks without $.
  • ExVariable → $marks = 72.

Questions

1

Define Variable without jargon. Then point at $marks = 72.

2

Where does Variable show up in a result script?

3

Which mistake makes $marks = 72 fail?

4

Dry-run $name = 'Asha'; and say the result.

Previous← Difference between Echo and PrintNextVariable Scope →
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.