PHP there are three types of arrays: Indexed arrays - Arrays with a numeric index. Associative arrays - Arrays with named keys. Multidimensional arrays - Arrays containing one or more arrays <!-- need to clear topic loop and php datatype PHP Data Types String. Integer. Float (floating point numbers - also called double) Boolean. Array. Object. NULL. 1.String Example:: echo "Hello"; echo 'Hello'; 2.Interger example:: $deci1 = 50; $deci2 = 654; // octal base integers $octal1 = 07; // hexadecimal base integers $octal = 0x45; $sum = $deci1 + $deci2; echo $sum; echo "\n\n"; //returns data type and value var_dump($sum) float example::$b = 5.34; 2.Boolean example:: $x = true; var_dump($x) Array Object Null What is Array ? $a=10; $a =10,20 ,40,"rahul"---------error3 =====>Array Use for store multiple value PHP, there are three types of arrays: 1.Indexed arrays - Arrays with a numeric index. // Example 1: Indexed array of fruits $fruits = array("Apple", "Banana", "Cherry", "Date"); // Example 2: Indexed array of car brands $cars = array("Toyota", "Honda", "Ford", "Chevrolet"); // Example 3: Indexed array of colors $colors = array("Red", "Green", "Blue", "Yellow"); // Example 4: Indexed array of countries $countries = array("USA", "Canada", "UK", "Australia"); // Example 5: Indexed array of programming languages $languages = array("PHP", "JavaScript", "Python", "Java"); 2.Associa tive arrays - Arrays with named keys. Example: $a= [ "sales"=>1000, "profit"=>500, "loss"=>400, "summary"=>"good", ]; / Example 2: Product details $product = array( "id" => 101, "name" => "Laptop", "brand" => "Dell", "price" => 800 ); // Example 3: Book details $book = array( "title" => "1984", "author" => "George Orwell", "year" => 1949, "genre" => "Dystopian" ); // Example 4: Student grades $studentGrades = array( "Alice" => "A", "Bob" => "B", "Charlie" => "C" ); // Example 5: City population $cityPopulation = array( "New York" => 8419000, "Los Angeles" => 3980000, "Chicago" => 2716000, "Houston" => 2328000 ); 3.Multidimensional arrays - Arrays containing one or more arrays array ( array (elements...), array (elements...), ... ) Example:: $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); example2 $Electric = array( array("Volvo", 22, 18), array("BMW", 15, 13), array("Saab", 5, 2), array("Land Rover", 17, 15) ); 4.Multidimensional Associative arrays -. Multidimensional associative array is often used to store data in group relation. example 1: $employees = array( "John Doe" => array( "age" => 30, "position" => "Manager", "salary" => 60000 ), "Jane Smith" => array( "age" => 25, "position" => "Developer", "salary" => 50000 ), "Sam Brown" => array( "age" => 28, "position" => "Designer", "salary" => 45000 ) ); Exaample:2 $movies = array( "Action" => array( "Mad Max" => array( "director" => "George Miller", "year" => 2015 ), "John Wick" => array( "director" => "Chad Stahelski", "year" => 2014 ) ), "Drama" => array( "The Shawshank Redemption" => array( "director" => "Frank Darabont", "year" => 1994 ), "Forrest Gump" => array( "director" => "Robert Zemeckis", "year" => 1994 ) ) ); example 3 $library = array( "Fiction" => array( "1984" => array( "author" => "George Orwell", "copies" => 4 ), "Brave New World" => array( "author" => "Aldous Huxley", "copies" => 6 ) ), "Non-Fiction" => array( "Sapiens" => array( "author" => "Yuval Noah Harari", "copies" => 5 ), "Educated" => array( "author" => "Tara Westover", "copies" => 3 ) ) ); // Example 4: Student grades $grades = array( "Math" => array( "Alice" => "A", "Bob" => "B" ), "Science" => array( "Alice" => "A+", "Bob" => "B+" ) ); // Example 3: Product inventory $inventory = array( "Electronics" => array( "Laptops" => array( "Dell" => 50, "HP" => 30 ), "Mobiles" => array( "Samsung" => 100, "Apple" => 80 ) ), "Furniture" => array( "Chairs" => 200, "Tables" => 150 ) );
June-06-2025 21:23:08
June-06-2025 11:35:05
June-06-2025 08:25:42
June-02-2025 21:09:41
June-02-2025 10:56:22
June-02-2025 10:27:58
June-02-2025 10:15:40
May-30-2025 19:20:40
May-30-2025 19:14:29
May-27-2025 21:52:18
May-27-2025 21:33:30
May-26-2025 17:11:41
May-26-2025 16:53:29
May-26-2025 16:50:59
May-13-2025 21:02:32
May-13-2025 17:46:23
May-12-2025 15:41:29