SlideShare a Scribd company logo
Array Methods
array_change_key_case
• Changes the case of all keys in an array
Syntax:
array_change_key_case(array $array, int $case)
case_lower: to convert to lower case
case_upper: to convert to upper case
Example:
<?php
$name =
array("abc"=>100,"def"=>200,"geh"=>300);
print_r(array_change_key_case($name,
CASE_UPPER));
?>
Output:
array_chunk
• Split an array into chunks
Syntax: array_chunk(array
$array, int $length, bool $preserve_keys)
Length:The size of each chunk
preserve_keys:When set to true keys will be
preserved. Default is false which will reindex the
chunk numerically
Example 1:
<?php
$input_array = array("a","b","c","d","e");
var_dump(array_chunk($input_array, 2,false));
?>
Output:
array_combine
• Creates an array by using one array for keys
and another for its values
Syntax:
array_combine(array $keys, array $values)
Example:
<?php
$a = array('Book', 'Pen', 'Diary');
$b =array('10', '20', '30');
$c = array_combine($a, $b);
print_r($c);
?>
Output:
array_merge
• Merge one or more arrays
• Syntax:
array_merge(array ...$arrays)
Example:
<?php
$a = array('10', '20', '30');
$b = array('40', '50', '60');
$c=array_merge($a,$b);
print_r($c);
?>
Output:
array_count_values
• Counts all the values of an array
Syntax:
array_count_values(array $array)
Example:
<?php
$a = array('10', '20', '30','40','20','10');
$c = array_count_values($a);
print_r($c);
?>
Output:
array_push
• Push one or more elements onto the end of
array
Syntax:
array_push(array &$array, mixed ...$values)
Example:
<?php
$fruits = array("kiwi", "grapes");
array_push($fruits, "apple", "mango");
print_r($fruits);
?>
Output:
array_pop
• Pop the element off the end of array
Syntax:
array_pop(array &$array)
Example:
<?php
$fruits = array("kiwi",
"grapes","mango","apple");
array_pop($fruits);
print_r($fruits);
?>
Output:
array_shift
• Shift an element off the beginning of array
Syntax:
array_shift(array &$array)
Example:
<?php
$stationary = array("pencil", "eraser",
"sharpner", "pen");
array_shift($stationary);
print_r($stationary);
?>
Output:
array_unshift
• Prepend one or more elements to the
beginning of an array
Syntax:
array_unshift(array &$array, mixed ...$values)
Example:
<?php
$stationary = array("pencil", "eraser",
"sharpner", "pen");
array_unshift($stationary,"glue");
print_r($stationary);
?>
Output:
sort
Sort an array in ascending order
Syntax:
sort(array &$array, int $flags = SORT_REGULAR)
Example:
<?php
$num = array(2,6,8,3,1,9);
asort($num);
var_dump($num);
?>
Output:
rsort
• Sort an array in descending order
Syntax:
rsort(array &$array, int $flags = SORT_REGULAR)
Example:
<?php
$num = array(2,6,8,3,1,9);
rsort($num);
print_r($num);
?>
Output:
asort
• Sort an array in ascending order and maintain
index association
Syntax:
asort(array &$array, int $flags = SORT_REGULAR)
Example:
<?php
$fruits = array(“l" => "lemon", "g" => "grapes",
"n" => "nuts", "a" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $valn";
}
?>
Output:
arsort
Sort an array in descending order and maintain
index association
Syntax:
arsort(array &$array, int $flags = SORT_REGULAR)
Example:
<?php
$fruits = array("l" => "lemon", "g" => "grapes",
"n" => "nuts", "a" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $valn";
}
?>
Output:
array_slice
• Extract a slice of the array
Syntax:
array_slice(
array $array,
int $offset,
?int $length = null,
bool $preserve_keys = false
)
Example:
<?php
$num = array(1,3,5,6,17,8,4,10);
$sliced=array_slice($num,3,4);
print_r($sliced);
?>
Output:
array_pad
• Pad array to the specified length with a value
Syntax:
array_pad(array $array, int $length, mixed $valu
e): array
• lengthNew size of the array.
• valueValue to pad if array is less than length.
Example:
<?php
$old_ar = array(1, 2, 3);
$result = array_pad($old_ar, 5, 0);
print_r($result);
?>
Output:
array_splice
• Remove a portion of the array and replace it with
something else
Syntax:
array_splice(
array &$array,
int $offset,
?int $length = null,
mixed $replacement = []
):
Example:
<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1,2, "apple");
var_dump($input);
?>
Output:
list
• Assign variables as if they were an array
Syntax:
list(mixed $var, mixed ...$vars = ?)
Example:
<?php
$info = array('Students', 'BCA', 'GGSIPU');
list($who, $what, $where) = $info;
echo "$who are doing $what from $where";
?
Output:

More Related Content

PPTX
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
PPTX
UNIT IV (4).pptx
PPT
Arrays in php
PPTX
Array functions for all languages prog.pptx
PPTX
Array functions using php programming language.pptx
PPTX
Chapter 2 wbp.pptx
PPTX
PHP Functions & Arrays
PPT
Class 4 - PHP Arrays
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
UNIT IV (4).pptx
Arrays in php
Array functions for all languages prog.pptx
Array functions using php programming language.pptx
Chapter 2 wbp.pptx
PHP Functions & Arrays
Class 4 - PHP Arrays

Similar to Array Methods.pptx (20)

PPTX
Arrays syntax and it's functions in php.pptx
PDF
Php tips-and-tricks4128
PPTX
Php functions
PPTX
Php Syntax Basics in one single course in nutshell
PDF
Php array
PDF
PHP tips and tricks
PDF
PHP Conference Asia 2016
PDF
Scripting3
PDF
Laravel collections an overview - Laravel SP
KEY
Achieving Parsing Sanity In Erlang
PDF
Array String - Web Programming
PPT
Php Using Arrays
PDF
Adventures in Optimization
PDF
PHP 101
DOCX
20220112 sac v1
KEY
Hidden treasures of Ruby
DOCX
PHP record- with all programs and output
PPT
Class 5 - PHP Strings
Arrays syntax and it's functions in php.pptx
Php tips-and-tricks4128
Php functions
Php Syntax Basics in one single course in nutshell
Php array
PHP tips and tricks
PHP Conference Asia 2016
Scripting3
Laravel collections an overview - Laravel SP
Achieving Parsing Sanity In Erlang
Array String - Web Programming
Php Using Arrays
Adventures in Optimization
PHP 101
20220112 sac v1
Hidden treasures of Ruby
PHP record- with all programs and output
Class 5 - PHP Strings
Ad

Recently uploaded (20)

PDF
SAHIL PROdhdjejss yo yo pdf TOCOL PPT.pdf
PPTX
"Fundamentals of Digital Image Processing: A Visual Approach"
PPTX
rorakshsjppaksvsjsndjdkndjdbdidndjdbdjom.pptx
PDF
ICT grade for 8. MATATAG curriculum .P2.pdf
PPT
Lines and angles cbse class 9 math chemistry
PDF
-DIGITAL-INDIA.pdf one of the most prominent
PPT
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
PPTX
Group 4 [BSIT-1C] Computer Network (1).pptx
PDF
Printing Presentation to show beginners.
PPTX
Unit-1.pptxgeyeuueueu7r7r7r77r7r7r7uriruru
PPTX
Wireless and Mobile Backhaul Market.pptx
PPTX
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
PPTX
Operating System Processes_Scheduler OSS
PDF
Dozuki_Solution-hardware minimalization.
PDF
2_STM32&SecureElements2_STM32&SecureElements
DOCX
Edukasi kultural untuk kita semua maka c
PDF
20A LG INR18650HJ2 3.6V 2900mAh Battery cells for Power Tools Vacuum Cleaner
PPTX
Prograce_Present.....ggation_Simple.pptx
PPTX
unit1d-communitypharmacy-240815170017-d032dce8.pptx
PDF
Presented by ATHUL KRISHNA.S_20250813_191657_0000.pdf
SAHIL PROdhdjejss yo yo pdf TOCOL PPT.pdf
"Fundamentals of Digital Image Processing: A Visual Approach"
rorakshsjppaksvsjsndjdkndjdbdidndjdbdjom.pptx
ICT grade for 8. MATATAG curriculum .P2.pdf
Lines and angles cbse class 9 math chemistry
-DIGITAL-INDIA.pdf one of the most prominent
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
Group 4 [BSIT-1C] Computer Network (1).pptx
Printing Presentation to show beginners.
Unit-1.pptxgeyeuueueu7r7r7r77r7r7r7uriruru
Wireless and Mobile Backhaul Market.pptx
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
Operating System Processes_Scheduler OSS
Dozuki_Solution-hardware minimalization.
2_STM32&SecureElements2_STM32&SecureElements
Edukasi kultural untuk kita semua maka c
20A LG INR18650HJ2 3.6V 2900mAh Battery cells for Power Tools Vacuum Cleaner
Prograce_Present.....ggation_Simple.pptx
unit1d-communitypharmacy-240815170017-d032dce8.pptx
Presented by ATHUL KRISHNA.S_20250813_191657_0000.pdf
Ad

Array Methods.pptx