Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,883 questions

51,809 answers

573 users

How to add elements to an empty array in PHP

4 Answers

0 votes
$array = array();

array_push($array, "php");
array_push($array, "c");
array_push($array, "c++");

print_r($array);





/*
run:
      
Array
(
    [0] => php
    [1] => c
    [2] => c++
)
      
*/

 



answered Jun 29, 2022 by avibootz
0 votes
$array = array();

array_push($array, "php", "c", "c++");

print_r($array);





/*
run:
      
Array
(
    [0] => php
    [1] => c
    [2] => c++
)
      
*/

 



answered Jun 29, 2022 by avibootz
0 votes
$array = array();

$array[] = "php";
$array[] = "c";
$array[] = "c++";

print_r($array);





/*
run:
      
Array
(
    [0] => php
    [1] => c
    [2] => c++
)
      
*/

 



answered Jun 29, 2022 by avibootz
0 votes
$array = array();

for ($i = 0; $i <= 5; $i++){
    $array[]  = $i + 10;  
}

print_r($array);




/*
run:
      
Array
(
    [0] => 10
    [1] => 11
    [2] => 12
    [3] => 13
    [4] => 14
    [5] => 15
)

*/

 



answered Jun 29, 2022 by avibootz

Related questions

1 answer 115 views
1 answer 128 views
1 answer 219 views
2 answers 162 views
1 answer 174 views
...