create array php

Solutions on MaxInterview for create array php by the best coders in the world

showing results for - "create array php"
Emilia
17 Aug 2016
1$array = array(
2    "foo" => "bar",
3    "bar" => "foo",
4);
Mavis
25 Jan 2016
1#Arrays
2
3<?php
4    #array is a variable that holds multiple values
5    /*
6    Three types of arrays
7        - Indexed
8        - associative
9        - Multi-dimensional
10    */
11    // Indexed array is the most common and easiest
12    $people = array('Kevin', 'Jeremy ', 'Sara');
13    $ids = array(23, 55, 12);
14    $cars = ['Honda', ' Toyota', 'Ford'];  // also an array
15    //add to an array
16    $cars[3] = ' Audi';
17    // you can use empty brackets and it will be added to the last one
18    $cars[] = ' Chevy';
19
20    echo $people[1];
21    echo $ids[1];
22    echo $cars[1];    
23    echo $cars[3];
24    echo $cars[4];
25    echo count($cars);
26    //you can also print the entire array
27    print_r($cars);
28    //to look at data type
29    echo var_dump($cars);
30
31    //Associative Arrays key pairs
32    $people1 = array('Kevin' => 35, 'Jeremy' => 23, 'Sara' => 19);
33    $ids1 = array(23 => 'Kevin', 55 => 'Jeremy', 12 => 'Sara');
34    echo $people1['Kevin'];
35    echo $ids1[23];
36    //add to these types of arrays
37    $people1['Jill'] = 44;
38    echo $people1['Jill'];
39    print_r($people1);
40    var_dump($people1);
41
42    //Multi-Dimensional Arrays aka an array within an array
43 
44    $cars2 = array(
45        array('Honda',20,10),
46        array('Toyota',30,20),
47        array('Ford',23,12)
48    );
49
50    echo $cars2[1][0];
51
52    
53?>
María
09 Apr 2017
1
2<?php
3$array array("foo""bar""hello""world");
4var_dump($array);
5?>
6
7
Timothée
29 Apr 2018
1
2<?php
3$array array(
4    "foo" => "bar",
5    "bar" => "foo",
6);
7
8// Utilisant la syntaxe de tableau courte
9$array = [
10    "foo" => "bar",
11    "bar" => "foo",
12];
13?>
14
15