What is array

Arrays
An arrayin PHP is a collection of key/value pairs.
 This means that it maps keys or indexes to values.
Array indexescan be either integers or strings
whereas values can be of any type.
Arrays in PHP are implemented using hash tables, which
 means that accessing a value has an average complexity.

array()construct Arrays can be declared using the array()language
 construct, which generally takes the following form elements inside
square brackets, [], are optional:

array([key =>] value, [key =>] value, ...)

The key is optional, and when it’s not specified, the key is
 automatically assigned one more than the largest previous
 integer key starting with 0. You can intermix the use with
 and without the key even within the same declaration.
The value itself can be of any PHP type, including an array.
 Arrays containing arrays give a similar result as multi-dimensional
 arrays in other languages.

Accessing Array Elements Array elements can be accessed by using
the $arr[key]notation, where keyis either an integer or string expression.
When using a constant string for key,make sure you don’t forget the single or
double quotes, such as $arr["key"]. This notation can be used for both reading
array elements and modifying or creating new elements.

$arr1 = array(1, 2, 3);
$arr2[0] = 1;
$arr2[1] = 2;
$arr2[2] = 3;
print_r($arr1);
print_r($arr2);

The print_r()function has not been covered yet in this book, but when it
is passed an array, it prints out the array’s contents in a readable way. You can
use this function when debugging your scripts.

Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
So, you can see that you can use both the array()construct
 and the $arr[key] notation to create arrays.
Usually, array()is used to declare arrays
whose elements are known at compile-time, and
 the $arr[key]notation is used when the elements
 are only computed at runtime.
PHP also supports a special notation, $arr[], where the key is
 not specified. When creating new array offsets using
 this notation , the key is automatically assigned as one
 more than the largest previous integer key.

Therefore, the previous example can be rewritten as follows:
$arr1 = array(1, 2, 3);
$arr2[] = 1;
$arr2[] = 2;
$arr2[] = 3;

$arr1 = array("name" => "John", "age" => 28);
$arr2["name"] = "John";
$arr2["age"] = 28;
if ($arr1 == $arr2) {
print '$arr1 and $arr2 are the same' . "\n";
}

Reading array values You can use the
 $arr[key]notation to read array values.
The next few examples build on top of the previous example:
print $arr2["name"];
if ($arr2["age"] < 35) {
print " is quite young\n";
}
Php Interview-questions-with-answers
Php code for valid number
Php file uploading code
Php by code
Advanced php
Php global variables
Top 550 php interview-questions

PHP Functions
Php tutorial - imagemagick
php.ini Basics
PHP Sessions
Cookies Versus Sessions
PHP Web-Related Variables
PHP ERRORS
maximum size of a file uploaded
Php Image upload
php file_get_contents
MySQL Data on the Web
What are GET and POST
php and pdf
$_ENV and $_SERVER
PEAR with php
SELECTING DATA PHP
prevent hijacking with PHP
LAMP
PHP MySQL Functions
PHP Zip File Functions
Substrings PHP
PHP Variable names
PHP magic methods
How to get current session id
Add variables into a session
$_GET , $_POST,$_COOKIE
different tables present in mysql
PHP CURL
php Sessions page
PHP-sorting an array
PHP-count the elements of array
Operators for If/Else Statements
PHP file uploading code
PHP global variables
Testing working using phpinfo
PHP Code for a Valid Number
PHP-Associative Arrays
PHP mvc tutorial
PHP get_meta_tags-Extracts
difference between print and echo
PHP best tutorial-PHP variables
Reading DOC file in PHP
PHP interview questions
convert time PHP
PHP implode array elements
header function-PHP
PHP-Renaming Files Directories
PHP Classes
in_array function in PHP
keep your session secure PHP
Web Application with PHP
What is SQL Injection
PHP-extract part of a string
PHP urlencode
PHP- know browser properties
PHP- Extracting Substrings
Checking Variable Values /Types
PHP-best 20 Open Source cms
IP AddressPHP
PHP-Scope Resolution Operator
how create new instance of object
how eliminate an object
PHP- ob_start
XML file using the DOM API
PHP- MVC
PHP- CAPTCHA
PHP- Position of a Value in an Array
PHP-Mail Functions
PHP-difference include vs require
calculate the sum of values in an array
PHP-total number of rows
Show unique records mysql
MySQL Triggers
MySQL data directory
MySQL Subqueries
PHP- Networking Functions
PHP- Operators
Restore database
Conditional Functions mysql
PHP-function overloading
Friend function
mysql_connect /mysql_pconnect
PHP-Error Control Operators
what is IMAP
Apache-Specific Functions
Send Email from a PHP Script
SQL inherently
WAMP, MAMP, LAMP
Php tutorial-SYMBOLS
Table Types-MySQL
PHP-Encryption data management
PHP Array
Running MySQL on Windows
Maximum Performance MySQL
XML-RPC
PHP-static variables
Advanced Database Techniques
FTP
Codeigniter
Apache Pool Size
Why NoSQL
MySQL Server Performance
Database software
SQL Interview Answers
PHP Redirect
PHP Interview Questions with Answers
Advanced PHP
Related Posts:
  • PHP Sessions The session_start( ) function is used to create a new session. A session is unique to the interaction between a browser and a web database application. If you use your browser to access several sites at once, you'll hav… Read More
  • php job in kolkata Learn web design & development with sitepoint tutorials, courses and books -  html5, css3, javascript, php, mobile app development, responsive web design.  In-depth tanking class/job analysis - tutorials and … Read More
  • PHP-Session Security Because a session may contain sensitive information, you need to treat the session as a possible security hole. Session security is necessary to create and implement a session. If someone is listening in or snoop… Read More
  • Abstract data type In programming, a data set defined by the programmer in terms of the information it can contain and the operations that can be performed with it. An abstract data type is more generalized than a data type constr… Read More
  • PHP Tutorial PHP Functions Php tutorial - imagemagick php.ini Basics PHP Sessions Cookies Versus Sessions PHP Web-Related Variables PHP ERRORS maximum size of a file uploaded Php Image upload php file_get_conte… Read More
  • php mvc tutorial for beginners-Model-View-Controller In most PHP web applications, you won’t have a strict MVC setup. In fact, it’s quite a lot of work to go full-on MVC with PHP. Getting a web project off the ground can be cumbersome and technically demanding, especially … Read More
  • PHP-Database-Basics-DB-Arrays Adding MySQL to PHP and combining the applications for your dynamic web site is a great start. But, it helps tremendously to structure your database right. We'll give you a solid understanding of both database de… Read More
  • mysql_fetch_array-code-demo  Example-1  mysql_fetch_array  code demo <?php//error_reporting(0); session_start(); include "include/connection.php"; include "include/functions.php"; if(@$_REQUEST['act']=='… Read More
  • PHP-simple Form Since you'll need a place for the user to enter a search query, let's begin by building a form to handle the user's input. Every form must have these basic components:The submission type defined with the met… Read More
  • PHP's variable-related functions PHP's variable-related functions are a key part of the language. Skilled programmers rely on them extensively to build robust code that uses type-checking. Functions like var_dump() and print_r() are also invaluable w… Read More
  • PHP-Associative Array When you are building an ordinary array, the array function requires the data, but doesn't require you to specify the indices. It automatically generates the index of each element by grabbing the next available intege… Read More
  • php.ini Basics After you have compiled or installed PHP, you can still change its behavior with the php.ini file. On Linux/UNIX systems, the default location for this file is /usr/local/php/lib or the lib subdirectory of the PHP installati… Read More
  • Database Functions-PHP MySQL PostgreSQL MS SQL (Microsoft) Chances are good that you will have at least one of these databases available to you (very good since MySQL and PostgreSQL are available for free download). There are four… Read More
  • Advanced Database Job PHP PHP supports the following databases in one form or another: MySQL— www.mysql.com mSQL— www.hughes.com.au MS SQL (Microsoft SQL server; on Win32 systems only) filePro (Read only)— www.fptech.com Informix— (fr… Read More
  • Php for-web developers   PHP MySQL Functions Free Hosting Requiring Cookies Web Application with PHP php -Mail Functions PHP Array Substrings PHP Comparison Operators for If/Else Statements Showing the Browser and I… Read More