Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

PHP Arrays

Indexed Arrays

$fruits = ["apple", "banana", "cherry"];
echo $fruits[0]; // apple

Associative Arrays

$ages = ["Alice" => 25, "Bob" => 30];
echo $ages["Alice"]; // 25

Multidimensional Arrays

$matrix = [
[1, 2, 3],
[4, 5, 6]
];

Common Functions

count($arr); // Array length
array_push($arr, $val); // Add to end
array_pop($arr); // Remove from end
sort($arr); // Sort ascending
array_merge($a, $b); // Merge arrays
in_array($val, $arr); // Check if exists