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

PHP · Theory

substr()

← All stacks

Theory

266/352

substr()

Priya only reaches for substr() when substr on Priya's board has to stay correct in lab hour.

substr() on the board: one substr step Priya can write from memory. Then say what substr on Priya's board looks like after.

Without substr(), lab hour gets messy and substr on Priya's board is hard to trust.

substr() shows up in lab hour. Name substr on Priya's board, not “a real-world scenario”.

If substr on Priya's board breaks under substr(), check copy-pasting substr without a dry-run first.

substr() is not a lonely heading. Priya ties it to substr on Priya's board.

One breath for substr(), then substr on Priya's board, then copy-pasting substr without a dry-run. Sit down.

Exam tip

Say substr() in one breath, then one substr step Priya can write from memory, then copy-pasting substr without a dry-run.

Example

<?php
// substr()
$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";
}

substr(): scores array, print avg, then high marks. Say the output.

Short notes

  • Defsubstr() — Priya uses it for substr on Priya's board in lab hour.
  • Rulesubstr() → one substr step Priya can write from memory.
  • Remembersubstr() + a .php page (lab hour).
  • Usesubstr() in lab hour (substr on Priya's board).
  • Trapsubstr() — copy-pasting substr without a dry-run.
  • Exsubstr() → substr on Priya's board.

Questions

1

Priya asks: why does substr() exist? Use substr on Priya's board.

2

If you skip substr(), what breaks in lab hour?

3

Viva: one wrong answer people give for substr().

4

Write the smallest substr() step on substr on Priya's board. What happens?

Previous← strtr()Nextsubstr_compare() →
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.