1
2<?php
3$array = array(
4 "foo" => "bar",
5 42 => 24,
6 "multi" => array(
7 "dimensional" => array(
8 "array" => "foo"
9 )
10 )
11);
12
13var_dump($array["foo"]);
14var_dump($array[42]);
15var_dump($array["multi"]["dimensional"]["array"]);
16?>
17
18
1
2<?php
3$array = array("foo", "bar", "hello", "world");
4var_dump($array);
5?>
6
7
1$cars = array('BMW', 'Ferrari', 'Honda');
2
3$str= implode(', ', $cars);
4echo $str; //array to string
5
6$arr = explode(', ', $str);
7echo json_encode($arr); //string to array
1<html>
2 <body>
3
4 <?php
5 /* First method to create array. */
6 $numbers = array( 1, 2, 3, 4, 5);
7
8 foreach( $numbers as $value ) {
9 echo "Value is $value <br />";
10 }
11
12 /* Second method to create array. */
13 $numbers[0] = "one";
14 $numbers[1] = "two";
15 $numbers[2] = "three";
16 $numbers[3] = "four";
17 $numbers[4] = "five";
18
19 foreach( $numbers as $value ) {
20 echo "Value is $value <br />";
21 }
22 ?>
23
24 </body>
25</html>
1
2<?php
3$array = array(
4 "foo" => "bar",
5 "bar" => "foo",
6);
7
8// Using the short array syntax
9$array = [
10 "foo" => "bar",
11 "bar" => "foo",
12];
13?>
14
15
1<html>
2 <body>
3
4
5 555
6 <?php
7 /* First method to create array. */
8 $numbers = array( 1, 2, 3, 4, 5);
9
10 foreach( $numbers as $value ) {
11 echo "Value is $value <br />";
12 }
13
14 /* Second method to create array. */
15 $numbers[0] = "one";
16 $numbers[1] = "two";
17 $numbers[2] = "three";
18 $numbers[3] = "four";
19 $numbers[4] = "five";
20
21 foreach( $numbers as $value ) {
22 echo "Value is $value <br />";
23 }
24 ?>
25
26 </body>
27</html>
1Array
2(
3 [user] => aaaaaaa
4 [pass] => 888
5 [color] => orange
6 [change_background] => Register
7)
8