Full Post Page
 

PHP Array and datatype

Category: PHP PROGRAMING & Written by Admin On April-10-2025 20:01:52

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 ) );

Comments

Share your thoughts about this post

Why Choose Us:

Experienced Instructors: Our team of experienced instructors are passionate about coding and dedicated to helping you succeed. With years of industry experience and a knack for teaching, they'll guide you every step of the way. Beginner-Friendly Content: Don't worry if you're new to coding. Our tutorials are designed with beginners in mind, starting from the fundamentals and gradually building up to more advanced topics. Updated Content: Coding is a rapidly evolving field, and we're committed to keeping our content up-to-date with the latest trends, technologies, and best practices. Community Support: Learning to code is more fun and effective when you're part of a supportive community. Join our online community forums to connect with fellow learners, share insights, and collaborate on projects. Get Started Today:



Recent Posts

Advance Js Fetch API Part-5

June-06-2025 21:23:08


Advance Js Promise Part-4

June-06-2025 11:35:05


Advance js oop part-3

June-06-2025 08:25:42


ExpressJs API With Image Crud-3

June-02-2025 21:09:41


NodeJs API-MVC-2

June-02-2025 10:56:22


ExpressJs API Crud-1

June-02-2025 10:27:58


ExpressJs Files upload

June-02-2025 10:15:40


NodeJS Cookie and CsrfToken

May-30-2025 19:20:40


ExpressJS Session

May-30-2025 19:14:29


ExpressJS NodeJs Crud Part-2

May-27-2025 21:52:18


ExpressJS NodeJS Crud Part-1

May-27-2025 21:33:30


ExpressJS Authentication

May-26-2025 17:11:41


NodeJS ExpressJS Files Upload

May-26-2025 16:53:29



Angular Introduction

May-13-2025 21:02:32



Advance Js part-1

May-12-2025 15:41:29