PHP Arrays Complete Guide
PHP Arrays Complete Guide
Example:
Example:
$student = array("name" => "Alice", "age" => 22, "city" => "Delhi");
Example:
$students = array(
);
Indexed Array:
Associative Array:
Multidimensional Array:
$matrix = array(
array(1, 2, 3),
array(4, 5, 6)
);
Adding Elements:
array_push($fruits, "Mango");
Removing Elements:
array_pop($fruits);
Merging Arrays:
$a = array(1, 2);
$b = array(3, 4);
$c = array_merge($a, $b);
print_r($c); // 1, 2, 3, 4
Comprehensive Guide on Arrays in PHP
Searching in Array:
Sorting Arrays:
sort($numbers); // Ascending
rsort($numbers); // Descending
HTML:
<form method="post">
<input type="submit">
</form>
PHP:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$numbers = $_POST['numbers'];
HTML:
Comprehensive Guide on Arrays in PHP
<form method="post">
<input type="submit">
</form>
PHP:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$student = $_POST['student'];
Example:
6. Best Practices
Example:
if (is_array($data)) {
echo htmlspecialchars($item);