PHP ARRAY
PHP array is an ordered map (contains value on the basis of key). It is used to hold multiple values of similar type in a single variable.
PHP ARRAY
A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
Advantage of PHP Array�
TYPES OF ARRAY
There are 3 types of array in PHP
PHP Indexed Array�
PHP Indexed Array�
Type 1 :
$season=array("summer","winter","spring","autumn");
Type 2 :
$season[0]="summer";
$season[1]="winter";
$season[2]="spring";
$season[3]="autumn";
PHP Associative Array��
PHP Associative Array�
Type 1 :
$salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000");
Type 2 :
$salary["Sonoo"]="350000";
$salary["John"]="450000";
$salary["Kartik"]="200000";
PHP Multidimensional Array��
PHP Multidimensional Array�
$emp = array
(
array(1,"sonoo",400000),
array(2,"john",500000),
array(3,"rahul",300000)
);
PHP extract() function��
PHP extract() function��
<?php
$info= array( );
$info['name']= "ajeet";
$info['office']= “msbte";
$info['city']= “mumbai";
$info['profile']= "HR";
extract($info);
echo $name;
echo $city;
?>
PHP compact() function��
PHP compact() function��
<?php
$var1 = "PHP";
$var2 = "JAVA";
$var3 = compact("var1","var2");
print_r($var3);
?>
PHP implode() function��
PHP implode() function��
Syntax :
Type 1.
string implode(separator, array);
Type 2.
implode (string $glue, array $pieces)
Type 3.
implode (array $pieces)
Separator ( , : + - etc.)
PHP explode() function��
PHP explode() function��
Syntax :
array explode(separator, OriginalString, NoOfElements);
PHP array_flip() function��
Syntax :
Array_flip(array);
PHP array_flip() function Example�
<?php
�$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");�$result=array_flip($a1);�print_r($result);�
?>
PHP unset() function�
The function unset() destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
PHP unset() function�
The function unset() destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
syntax :- void unset ( mixed $var , mixed $vars )
PHP unset() function Example�
<?php
$a = "Welcome TO PHP!";
echo "The value of 'a' before unset: " . $a . "<br>";
unset($a);
echo "The value of 'a' after unset: " . $a;
?>
The value of 'a' before unset: Welcome To PHP!��Warning: Undefined variable $a in C:\xampp\htdocs\php\array\unset_function.php on line 5�The value of 'a' after unset:
PHP unset() function Output�