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,900 questions

51,831 answers

573 users

How to initialize an array in PHP

6 Answers

0 votes
$arr = array(3, 9, 0, 5, 1);

print_r($arr);




/*
run:

Array
(
    [0] => 3
    [1] => 9
    [2] => 0
    [3] => 5
    [4] => 1
)
    
*/

 



answered Jul 2, 2022 by avibootz
0 votes
$arr = array("php"=>99, "c"=>107, "c++"=>21, "java"=>91);
  
print_r($arr);
 
 
 
 
/*
run:
 
Array
(
    [php] => 99
    [c] => 107
    [c++] => 21
    [java] => 91
)
 
*/

 



answered Jul 2, 2022 by avibootz
0 votes
$arr = array("php"=>"aaa", "c"=>"bbb", "c++"=>"xxx", "java"=>"yyy");
 
print_r($arr);




/*
run:

Array
(
    [php] => aaa
    [c] => bbb
    [c++] => xxx
    [java] => yyy
)

*/

 



answered Jul 2, 2022 by avibootz
0 votes
$arr = array(2=>"php", 1=>"c", 4=>"c++", 3=>"java");

print_r($arr);




/*
run:

Array
(
    [2] => php
    [1] => c
    [4] => c++
    [3] => java
)

*/

 



answered Jul 2, 2022 by avibootz
0 votes
$arr = array (
        "first"  => array(2=>"php", 1=>"c", 4=>"c++", 3=>"java"),
        "second" => array(3, 9, 0, 5, 1),
        "third"  => array("php"=>"aaa", "c"=>"bbb", "c++"=>"xxx", "java"=>"yyy")
    );

print_r($arr);




/*
run:

Array
(
    [first] => Array
        (
            [2] => php
            [1] => c
            [4] => c++
            [3] => java
        )

    [second] => Array
        (
            [0] => 3
            [1] => 9
            [2] => 0
            [3] => 5
            [4] => 1
        )

    [third] => Array
        (
            [php] => aaa
            [c] => bbb
            [c++] => xxx
            [java] => yyy
        )

)

*/

 



answered Jul 2, 2022 by avibootz
0 votes
$arr = [4, 17, 52, 84, 198, 9063];

print_r($arr);

 
/*
run:
 
Array
(
    [0] => 4
    [1] => 17
    [2] => 52
    [3] => 84
    [4] => 198
    [5] => 9063
)
     
*/

 



answered Aug 16, 2024 by avibootz

Related questions

4 answers 322 views
1 answer 107 views
2 answers 136 views
3 answers 152 views
1 answer 103 views
...