OnlineCBT Logo OnlineCBT
PHP · LESSON 9

Array Functions: count, array_merge, array_map, in_array

By Ratan Updated: 16 Oct 2026

Manipulate array data efficiently using PHP array functions.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. Overview of PHP Array Functions

PHP provides a comprehensive suite of built-in array manipulation functions that streamline data handling without manual nested loops.

2. Array Size and Key Checking

  • count($array): Returns total element count.
  • in_array($value, $array): Checks if a value exists within an array.
  • array_key_exists($key, $array): Checks if a specified key exists in an associative array.
";
}

3. Merging and Slicing Arrays

4. Functional Transformations: array_map, array_filter, array_reduce

 $n % 2 === 0);

// array_map: double every element
$doubled = array_map(fn($n) => $n * 2, $numbers);

// array_reduce: sum all elements into a single aggregate
$totalSum = array_reduce($numbers, fn($carry, $item) => $carry + $item, 0);

5. Sorting Arrays

Function Key / Value Preserved Order
sort() Values (re-indexes keys) Ascending
rsort() Values (re-indexes keys) Descending
asort() Maintains key-value associations Ascending by Value
ksort() Maintains key-value associations Ascending by Key

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat