- Home
-
HTML
HTML Introduction HTML Tags HTML Elements HTML Attributes HTML Heading HTML Paragraph HTML Formatting HTML Quotations HTML Comments HTML Styles HTML Color HTML CSS HTML Images HTML Favicon HTML Links HTML DIV HTML Tables HTML Table Size HTML Table Head Table Padding & Spacing Table colspan rowspsn HTML Table Styling HTML Colgroup HTML List HTML Block & Inline HTML Classes HTML Id HTML Iframes HTML Head HTML Layout HTML Semantic Elements HTML Style Guide HTML Forms HTML Form Attribute HTML Form Element HTML input type HTML Computer code HTML Entity HTML Symbol HTML Emojis HTML Charset HTML Input Form Attribute HTML URL Encoding
-
CSS
CSS Introduction CSS Syntax CSS Selector How To Add CSS CSS Comments CSS Colors CSS Background color CSS background-image CSS Borders CSS Margins CSS Height, Width and Max-width CSS Box Model CSS Outline CSS Text CSS Fonts CSS Icon CSS Links CSS Tables CSS Display CSS Maximum Width CSS Position z-index Property
- JavaScript
-
JQuery
What is jQuery? Benefits of using jQuery Include jQuery Selectors. Methods. The $ symbol and shorthand. Selecting elements Getting and setting content Adding and removing elements Modifying CSS and classes Binding and Unbinding events Common events: click, hover, focus, blur, etc Event delegation Using .on() for dynamic content Showing and hiding elements Fading elements in and out Sliding elements up and down .animate() Understanding AJAX .ajax() .load(), .get(), .post() Handling responses and errors. Parent Chlid Siblings Filtering Elements Using find Selecting form elements Getting form values Setting form values Form validation Handling form submissions jQuery plugins Sliders plugins $.each() $.trim() $.extend() Data attributes Debugging jQuery code
-
Bootstrap 4
What is Bootstrap Benefits of using Setting up Container Row and Column Grid Classes Breakpoints Offsetting Columns Column Ordering Basic Typography Text Alignment Text colors Backgrounds Display Font Size Utilities Buttons Navs and Navbar Forms Cards Alerts Badges Progress Bars Margin Padding Sizing Flexbox Dropdowns Modals Tooltips Popovers Collapse Carousel Images Tables Jumbotron Media Object
- Git
-
PHP
PHP Introduction PHP Installation PHP Syntax PHP Comments PHP Variable PHP Echo PHP Data Types PHP Strings PHP Constant PHP Maths PHP Number PHP Operators PHP if else & if else if PHP Switch PHP Loops PHP Functions PHP Array PHP OOps PHP Class & Object PHP Constructor PHP Destructor PHP Access Modfiers PHP Inheritance PHP Final Keyword PHP Class Constant PHP Abstract Class PHP Superglobals PHP Regular Expression PHP Interfaces PHP Static Method PHP Static Properties PHP Namespace PHP Iterable PHP Form Introduction PHP Form Validation PHP Complete Form PHP Date and Time PHP Include Files PHP - Files & I/O File Upload PHP Cookies PHP SESSION PHP Filters PHP Callback Functions PHP JSON PHP AND Exceptions PHP Connect database
-
MY SQL
SQL Introduction Syntax Select statement Select Distinct WHERE Clause Order By SQL AND Operator SQL OR Operator SQL NOT Operator SQL LIKE SQL IN SQL BETWEEN SQL INSERT INTO SQL NULL Values SQL UPDATE SQL DELETE SQL TOP, LIMIT, FETCH FIRST or ROWNUM Clause SQL MIN() and MAX() Functions SQL COUNT() Function SQL SUM() SQL AVG() SQL Aliases SQL JOIN SQL INNER JOIN SQL LEFT JOIN SQL RIGHT JOIN SQL FULL OUTER JOIN SQL Self Join SQL UNION SQL GROUP BY SQL HAVING SQL EXISTS SQL ANY and ALL SQL SELECT INTO SQL INSERT INTO SELECT SQL CASE SQL NULL Functions SQL Stored Procedures SQL Comments SQL Operators SQL CREATE DATABASE SQL DROP DATABASE SQL BACKUP DATABASE SQL CREATE TABLE SQL DROP TABLE SQL ALTER TABLE SQL Constraints SQL NOT NULL SQL UNIQUE Constraint SQL PRIMARY KEY SQL FOREIGN KEY SQL CHECK Constraint SQL CREATE INDEX SQL AUTO INCREMENT SQL Dates SQL Views SQL Injection SQL Hosting SQL Data Types
PHP Array
PHP arrays are flexible and powerful data structures that allow you to store multiple values in a single variable. They can hold different types of values such as integers, strings, or even other arrays. There are three main types of arrays in PHP:
- Indexed Arrays: Arrays with a numeric index.
- Associative Arrays: Arrays where the keys are named.
- Multidimensional Arrays: Arrays containing one or more arrays.
Let's explore each type with examples and outputs.
Indexed Arrays
Indexed arrays use numeric indices to access their values.
<?php
$fruits = array("Apple", "Banana", "Cherry");
// Accessing values
echo $fruits[0]; // Output: Apple
echo $fruits[1]; // Output: Banana
echo $fruits[2]; // Output: Cherry
// Adding values
$fruits[] = "Date"; // Adds "Date" at the end of the array
// Looping through the array
foreach($fruits as $fruit) {
echo $fruit . " ";
}
// Output: Apple Banana Cherry Date
?>
Associative Arrays
Associative arrays use named keys to access their values.
<?php
$ages = array("Peter" => 35, "Ben" => 37, "Joe" => 43);
// Accessing values
echo $ages["Peter"]; // Output: 35
echo $ages["Ben"]; // Output: 37
echo $ages["Joe"]; // Output: 43
// Adding values
$ages["Anna"] = 25; // Adds "Anna" => 25 to the array
// Looping through the array
foreach($ages as $name => $age) {
echo "$name is $age years old. ";
}
// Output: Peter is 35 years old. Ben is 37 years old. Joe is 43 years old. Anna is 25 years old.
?>
Multidimensional Arrays
Multidimensional arrays contain one or more arrays within them.
<?php
$students = array(
"John" => array("Math" => 85, "Science" => 78, "English" => 90),
"Jane" => array("Math" => 92, "Science" => 88, "English" => 84),
"Doe" => array("Math" => 70, "Science" => 75, "English" => 80)
);
// Accessing values
echo $students["John"]["Math"]; // Output: 85
echo $students["Jane"]["Science"]; // Output: 88
echo $students["Doe"]["English"]; // Output: 80
// Looping through the array
foreach($students as $name => $subjects) {
echo "$name's scores: ";
foreach($subjects as $subject => $score) {
echo "$subject: $score ";
}
echo "\n";
}
// Output:
// John's scores: Math: 85 Science: 78 English: 90
// Jane's scores: Math: 92 Science: 88 English: 84
// Doe's scores: Math: 70 Science: 75 English: 80
?>
Functions for Arrays
PHP provides a wide range of functions to manipulate arrays. Here are a few commonly used ones:
count($array)
: Returns the number of elements in an array.array_merge($array1, $array2)
: Merges two or more arrays.array_keys($array)
: Returns all the keys of an array.array_values($array)
: Returns all the values of an array.in_array($value, $array)
: Checks if a value exists in an array.
Example
<?php
$colors = array("Red", "Green", "Blue");
// Count elements
echo count($colors); // Output: 3
// Merge arrays
$moreColors = array("Yellow", "Purple");
$allColors = array_merge($colors, $moreColors);
// Print merged array
foreach($allColors as $color) {
echo $color . " ";
}
// Output: Red Green Blue Yellow Purple
// Check if a value exists
if(in_array("Green", $allColors)) {
echo "Green is in the array.";
} else {
echo "Green is not in the array.";
}
// Output: Green is in the array.
?>
These examples cover the basics of PHP arrays. They are fundamental for managing and manipulating collections of data in PHP.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2024 © All rights reserved.