pivopen May 1, 2025 0 4
pivopen May 1, 2025 0 6
pivopen Apr 26, 2025 0 9
pivopen May 3, 2025 0 3
pivopen May 3, 2025 0 5
pivopen May 3, 2025 0 4
pivopen May 1, 2025 0 5
Join our subscribers list to get the latest news, updates and special offers directly in your inbox
PHP Tutorials
To add items to an array in PHP, you can use several methods depending on the type of array (indexed or associative). Here are the common ways:
$fruits = ["apple", "banana"]; $fruits[] = "orange"; // Add at the end array_push($fruits, "grape", "melon"); // Add multiple items print_r($fruits);
$user = [ "name" => "John", "age" => 30 ]; $user["email"] = "john@example.com"; // Add new key-value pair print_r($user);
$a = [1, 2]; $b = [3, 4]; $c = array_merge($a, $b); // Combine arrays print_r($c);
+
$a = ["a" => 1]; $b = ["b" => 2]; $c = $a + $b; // $a values take precedence if keys overlap print_r($c);
Previous Article
Next Article
Like
Dislike
Love
Funny
Angry
Sad
Wow
pivopen
pivopen May 2, 2025 0 2
pivopen May 2, 2025 0 3
pivopen May 3, 2025 0 2
pivopen May 1, 2025 0 8