'; print_r($months); echo ''; // Getting value from index echo '
'; print_r($months[1]); echo ''; // Short hand $months = [ 'January', // Index = 0 'February', // Index = 1 'March', // Index = 2 ]; /* Associative Arrays */ $months = [ 'month1' => 'January', 'month2' => 'February', 'month3' => 'March' ]; echo '
'; print_r($months); echo ''; echo '
'; print_r($months['month1']); echo ''; /* Working with Arrays */ // range() $numbers = range(1, 10); // Same as $numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; echo '
'; print_r($numbers); echo ''; $numbers = range(1, 10, 2); // Same as $numbers = [1, 3, 5, 7, 9]; echo '
'; print_r($numbers); echo ''; // Adding to arrays $months = [ 'January', // Index = 0 'February', // Index = 1 'March', // Index = 2 ]; // Add to index 3 $months[3] = 'April'; // Change index 2 $months[2] = 'May'; // Add to end of array $months[] = 'June'; echo '
'; print_r($months); echo ''; /* Merging Arrays */ $sem1grades = [ 'math' => 90, 'chemistry' => 67, 'biology' => 88, 'history' => 45, 'gym' => 60, ]; $sem2grades = [ 'philosophy' => 87, 'art' => 99, 'physics' => 71, 'gym' => 60, ]; // array_merge() $allGrades = array_merge($sem1grades, $sem2grades); echo '
'; print_r($allGrades); echo ''; // Array Union $allGrades = $sem1grades + $sem2grades; echo '
'; print_r($allGrades); echo ''; /* Multidimensional arrays */ $meats = [ 'Pepperoni', 'Bacon', 'Ham', ]; $cheeses = [ 'Mozzarella', 'Cheddar', 'Swiss', ]; $veggies = [ 'Onions', 'Peppers', 'Mushrooms', ]; $toppings = [ 'Meats' => $meats, 'Cheeses' => $cheeses, 'Veggies' => $veggies, 'Size' => 'Medium', ]; echo $toppings['Veggies'][1]; echo '
'; print_r($array1); echo ''; // rsort() rsort($array1); echo '
'; print_r($array1); echo ''; $assocArray = [ 'a' => 3, 'b' => 1, 'c' => 4, ]; // asort() asort($assocArray); echo '
'; print_r($assocArray); echo ''; $assocArray = [ 'a' => 3, 'b' => 1, 'c' => 4, ]; // ksort() ksort($assocArray); echo '
'; print_r($assocArray); echo '';