AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Array


<< Previous Page
HTML tutorial
Next Page >>
HTML tutorial

PHP Tutorial » PHP Arrays

What is an Array?

An array is a special variable that can hold more values at the some time.

In PHP, there are three types of arrays:

Create an Array in PHP
array() function is used to create an array:

Syntax:

array();

 

Indexed or Numeric array

To loop through array and display all the values of an Indexed (Numeric) array, we use a "for" loop, as this:

Example (this is HTML - PHP editor, change text, values on this window)
<?php
$my_cars = array("Peugeot", "BMW", "Volvo", "Toyota", "Renault");
$arr_length = count($my_cars);

for($a = 0; $a < $arr_length; $a++) {
echo $my_cars[$a];
echo "<br>";
}
?>

 

Related subjects:
What is an array Convert array to string comma Array to comma separated

Tags: php array: push, length, append, function, merge, add, to string, size, foreach, key, key value, of arrays, filter
What are PHP arrays?
How do you create array in PHP?
What are the three types of arrays in PHP?
What is array key PHP?

 

PHP Associative Arrays

Associative arrays are more o less the same as numeric arrays in term of functionality but they are different in terms of their index

Associative arrays are arrays that use named keys that you assign to them.

We show you an example: Loop Through an Associative Array

Example (this is HTML - PHP editor, change text or on this window)
<?php
$user_age = array("Chris"=>"32", "Benony"=>"27",
"Johny"=>"23", "Ana-Marie"=>"29", "Maru"=>"43");

foreach($user_age as $a => $a_value) {
echo "Age for " . $a . ", is =" . $a_value;
echo "<br>";
}
?>

 

PHP Multidimensional Arrays

A multi-dimensional array is an array containing one or more arrays.

Example (this is HTML - PHP editor, change text or value on this window)
<?php
$carsstsold = array (
array("Peugeot",24,14),
array("Renault",18,11),
array("BMW",9,2),
array("Land Rover",17,12),
array("Volvo",16,7)
);

echo $carsstsold[0][0].": - In stock: ".$carsstsold[0][1].", sold: ".$carsstsold[0][2].".<br>";
echo $carsstsold[1][0].": - In stock: ".$carsstsold[1][1].", sold: ".$carsstsold[1][2].".<br>";
echo $carsstsold[2][0].": - In stock: ".$carsstsold[2][1].", sold: ".$carsstsold[2][2].".<br>";
echo $carsstsold[3][0].": - In stock: ".$carsstsold[3][1].", sold: ".$carsstsold[3][2].".<br>";
echo $carsstsold[4][0].": - In stock: ".$carsstsold[4][1].", sold: ".$carsstsold[4][2].".<br>";
?>

 



Tags: php array: push, length, append, function, merge, add, to string, size, foreach, key, key value, of arrays, filter
What are PHP arrays?
How do you create array in PHP?
What are the three types of arrays in PHP?
What is array key PHP?


PHP Array - What is an Array? - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...