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

PHP · Theory

Indexed Array

← All stacks

Theory

34/352

Indexed Array

An array holds many values. Indexed: $marks = [72, 40, 88]; $marks[0] is 72. Associative: $student = ['name' => 'Asha', 'roll' => 12]; $student['name'] is Asha. foreach ($student as $key => $value) walks them.

count($arr) length. array_push / $arr[] = 10 to add. PHP arrays are ordered maps — that’s why both styles work.

Trap — mixing 0 and '0' carelessly. Trap: foreach ($arr as &$v) then using $v later (reference leak).

Exam tip

Indexed [72,40] and associative ['name'=>'Asha'].

Example

<?php
$langs = ["PHP", "JS", "SQL"];
$langs[] = "Python";
foreach ($langs as $i => $lang) {
  echo "$i: $lang\n";
}

Indexed Array — pHP arrays are ordered maps. foreach walks key and value.

Short notes

  • DefArray = list or name→value map.
  • Rule[1,2] or ['name'=>'Asha']. foreach to loop.
  • Trapforeach by reference leftover.

Questions

1

Two array styles?

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