Example 1: php arrays
#Arrays
<?php
#array is a variable that holds multiple values
$people = array('Kevin', 'Jeremy ', 'Sara');
$ids = array(23, 55, 12);
$cars = ['Honda', ' Toyota', 'Ford'];
$cars[3] = ' Audi';
$cars[] = ' Chevy';
echo $people[1];
echo $ids[1];
echo $cars[1];
echo $cars[3];
echo $cars[4];
echo count($cars);
print_r($cars);
echo var_dump($cars);
$people1 = array('Kevin' => 35, 'Jeremy' => 23, 'Sara' => 19);
$ids1 = array(23 => 'Kevin', 55 => 'Jeremy', 12 => 'Sara');
echo $people1['Kevin'];
echo $ids1[23];
$people1['Jill'] = 44;
echo $people1['Jill'];
print_r($people1);
var_dump($people1);
$cars2 = array(
array('Honda',20,10),
array('Toyota',30,20),
array('Ford',23,12)
);
echo $cars2[1][0];
?>
Example 2: php arrays
$nums = [1, 2, 3, 4, 5];
Example 3: php array
$array = ['cheese', 'ham', 'potato'];
var_dump($array);
Example 4: php array functions
array_change_key_case() Changes all keys in an array to lowercase or uppercase
array_chunk() Splits an array into chunks of arrays
array_column() Returns the values from a single column in the input array
array_combine() Creates an array by using the elements from one "keys" array and one "values" array
array_count_values() Counts all the values of an array
array_diff() Compare arrays, and returns the differences (compare values only)
array_diff_assoc() Compare arrays, and returns the differences (compare keys and values)
array_diff_key() Compare arrays, and returns the differences (compare keys only)
array_diff_uassoc() Compare arrays, and returns the differences (compare keys and values, using a user-defined key comparison function)
array_diff_ukey() Compare arrays, and returns the differences (compare keys only, using a user-defined key comparison function)
array_fill() Fills an array with values
array_fill_keys() Fills an array with values, specifying keys
array_filter() Filters the values of an array using a callback function
array_flip() Flips/Exchanges all keys with their associated values in an array
array_intersect() Compare arrays, and returns the matches (compare values only)
array_intersect_assoc() Compare arrays and returns the matches (compare keys and values)
array_intersect_key() Compare arrays, and returns the matches (compare keys only)
array_intersect_uassoc() Compare arrays, and returns the matches (compare keys and values, using a user-defined key comparison function)
array_intersect_ukey() Compare arrays, and returns the matches (compare keys only, using a user-defined key comparison function)
Example 5: PHP Arrays
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>