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

PHP · Theory

array_diff()

← All stacks

Theory

114/352

array_diff()

array_diff() is a PHP array helper. You pass an array, you get a new array or a boolean/count. Example: in_array(40, $marks), array_merge($a,$b), count($marks).

foreach is still how you loop. Functions don’t replace understanding [ ] vs ['name'=>].

Trap — expecting the original array to change when the function returns a copy (array_map).

Exam tip

array_diff(): one array, one function call, say the result.

Example

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

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

Short notes

  • Defarray_diff() — PHP array function.
  • RuleRead the return value. foreach to walk.
  • TrapThinking it always edits in place.

Questions

1

What is array_diff()?

114 / 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.