SlideShare a Scribd company logo
PHP ARRAY
FUNCTIONS
array_combine()
• The array_combine() function creates an array by using the elements
from one "keys" array and one "values" array.
• array_combine(keys, values)
<?php
$name=array("Manoj","Rahul","Aneesh");
$marks=array("75","89","44");
$c=array_combine($name,$marks);
print_r($c);
?>
OUTPUT:
Array ( [Manoj] => 75 [Rahul] => 89 [Aneesh] => 44 )
array_chunk()
• The array_chunk() function splits an array into chunks of new
arrays.
• array_chunk(array, size, preserve_key)
<?php
$courses=array("PHP","Laravel","Node
js","HTML","CSS","ASP.NET");
print_r(array_chunk($courses,2));
?>
OUTPUT:
Array ( [0] => Array ( [0] => PHP [1] => Laravel ) [1] => Array ( [0]
=> Node js [1] => HTML ) [2] => Array ( [0] => CSS [1] =>
ASP.NET ) )
array_chunk()
<?php
$courses=array("a"=>"PHP","b"=>"Laravel","c"=>"Node
js","d"=>"HTML","e"=>"CSS","f"=>"ASP.NET");
print_r(array_chunk($courses,2));
?>
OUTPUT:
Array ( [0] => Array ( [0] => PHP [1] => Laravel ) [1] =>
Array ( [0] => Node js [1] => HTML ) [2] => Array ( [0] =>
CSS [1] => ASP.NET ) )
array_chunk()
<?php
$courses=array("a"=>"PHP","b"=>"Laravel","c"=>"Node
js","d"=>"HTML","e"=>"CSS","f"=>"ASP.NET");
print_r(array_chunk($courses,2, true));
?>
OUTPUT:
Array ( [0] => Array ( [a] => PHP [b] => Laravel ) [1] =>
Array ( [c] => Node js [d] => HTML ) [2] => Array ( [e] =>
CSS [f] => ASP.NET ) )
array_count_values()
• The array_count_values() function counts all the values of
an array.
• array_count_values(array)
<?php
$a=array("Block 33","Block 34","Block 34","Block 36","Block
36");
print_r(array_count_values($a));
?>
OUTPUT:
Array ( [Block 33] => 1 [Block 34] => 2 [Block 36] => 2 )
array_diff()
• The array_diff() function compares the values of two (or
more) arrays, and returns the differences.
• This function compares the values of two (or more)
arrays, and return an array that contains the entries from
array1 that are not present in array2 or array3, etc.
• array_diff(array1, array2, array3, ...)
array_diff()
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yello
w");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$a3=array("h"=>"magenta","i"=>"seagreen");
$result=array_diff($a1,$a2);
print_r($result);
?>
OUTPUT:
Array ( [d] => yellow )
array_flip()
• The array_flip() function flips/exchanges all keys with their
associated values in an array.
• array_flip(array)
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"
);
$result=array_flip($a1);
print_r($result);
?>
OUTPUT:
Array ( [red] => a [green] => b [blue] => c [yellow] => d )
array_flip()
<?php
$a1=array("red","green","blue","yellow");
$result=array_flip($a1);
print_r($result);
?>
OUTPUT:
Array ( [red] => 0 [green] => 1 [blue] => 2 [yellow] => 3 )
array_intersect()
• The array_intersect() function compares the values of two (or more)
arrays, and returns the matches.
• array_intersect(array1, array2, array3, ...)
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$a3=array("red","blue");
$result=array_intersect($a1,$a2,$a3);
print_r($result);
?>
OUTPUT:
Array ( [a] => red [c] => blue )
array_merge()
• The array_merge() function merges one or more arrays into
one array.
• array_merge(array1, array2, array3, ...)
<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
$a3=array("c"=>"orange","b"=>"magenta");
print_r(array_merge($a1,$a2,$a3));
?>
OUTPUT:
Array ( [a] => red [b] => magenta [c] => orange )
array_merge()
<?php
$a1=array("red","green", "blue");
$a2=array("blue","yellow");
print_r(array_merge($a1,$a2));
?>
OUTPUT:
Array ( [0] => red [1] => green [2] => blue [3] => blue [4] =>
yellow )
array_pop()
• The array_pop() function deletes the last element of an
array.
• array_pop(array)
<?php
$a=array("red","green","blue");
array_pop($a);
print_r($a);
?>
OUTPUT:
Array ( [0] => red [1] => green )
array_pop()
<?php
$a=array("a"=>"red","b"=>"green","c"=>"blue");
array_pop($a);
print_r($a);
?>
OUTPUT:
Array ( [a] => red [b] => green )
array_push()
• The array_push() function inserts one or more elements
to the end of an array.
• array_push(array, value1, value2, ...)
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
OUTPUT:
Array ( [0] => red [1] => green [2] => blue [3] => green )
array_push()
<?php
$a=array("a"=>"red","b"=>"green");
array_push($a,"blue","yellow");
print_r($a);
?>
OUTPUT:
Array ( [a] => red [b] => green [0] => blue [1] => yellow )
array_reverse()
• The array_reverse() function returns an array in the
reverse order.
• array_reverse(array, preserve)
<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>
OUTPUT:
Array ( [c] => Toyota [b] => BMW [a] => Volvo )
array_reverse()
• Pass true value to preserve the key
<?php
$a=array("Volvo","BMW","Toyota");
print_r(array_reverse($a, true));
?>
OUTPUT:
Array ( [2] => Toyota [1] => BMW [0] => Volvo )
array_search()
• The array_search() function search an array for a value
and returns the key.
• array_search(value, array, strict)
<?php
$a=array("a"=>"red","b"=>"green","c"=>"blue");
echo array_search("red",$a);
?>
OUTPUT:
a
array_search()
<?php
$a=array("a"=>"1","b"=>1,"c"=>"1");
echo array_search(1,$a,true);
?>
OUTPUT:
b
array_slice()
• The array_slice() function returns selected parts of an array.
• array_slice(array, start, length, preserve)
<?php
$a=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"brown");
print_r(array_slice($a,1,2));
echo "<br>";
$a=array("red","green","blue","yellow","brown");
print_r(array_slice($a,1,2,true));
?>
OUTPUT:
Array ( [b] => green [c] => blue )
Array ( [1] => green [2] => blue )
array_column()
• The array_column() function returns the values from a single column in the input
array.
• array_column(array, column_key, index_key)
<?php
$result = array(
array('name'=>'Manoj','cgpa'=>6.7,'status'=>'pass'),
array('name'=>"Shalini",'cgpa'=>9.8,'status'=>'pass'),
array('name'=>'Mani','cgpa'=>3.2,'status'=>'fail')
);
$name = array_column($result, 'name');
print_r($name);
?>
OUTPUT:
Array ( [0] => Manoj [1] => Shalini [2] => Mani )
array_column()
<?php
$result = array(
array('name'=>'Manoj','cgpa'=>6.7,'status'=>'pass'),
array('name'=>"Shalini",'cgpa'=>9.8,'status'=>'pass'),
array('name'=>'Mani','cgpa'=>3.2,'status'=>'fail')
);
$names = array_column($result, 'status', 'name');
print_r($names);
?>

More Related Content

Similar to Array functions using php programming language.pptx (20)

PDF
Php tips-and-tricks4128
PrinceGuru MS
 
PPTX
Array Methods.pptx
stargaming38
 
DOCX
List of all php array functions
Chetan Patel
 
PDF
PHP and MySQL Tips and tricks, DC 2007
Damien Seguy
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
PPTX
Arrays syntax and it's functions in php.pptx
NikhilVij6
 
PPTX
Chap 3php array part 3
monikadeshmane
 
PDF
PHP tips and tricks
Damien Seguy
 
PPTX
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ayushmishraaa09
 
PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
PPT
Php Chapter 2 3 Training
Chris Chubb
 
PPTX
Arrays in PHP
davidahaskins
 
PDF
4.1 PHP Arrays
Jalpesh Vasa
 
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PPTX
Php functions
JIGAR MAKHIJA
 
PDF
Array String - Web Programming
Amirul Azhar
 
PPTX
PHP array 1
Mudasir Syed
 
PDF
lab4_php
tutorialsruby
 
PDF
lab4_php
tutorialsruby
 
Php tips-and-tricks4128
PrinceGuru MS
 
Array Methods.pptx
stargaming38
 
List of all php array functions
Chetan Patel
 
PHP and MySQL Tips and tricks, DC 2007
Damien Seguy
 
PHP Functions & Arrays
Henry Osborne
 
Arrays syntax and it's functions in php.pptx
NikhilVij6
 
Chap 3php array part 3
monikadeshmane
 
PHP tips and tricks
Damien Seguy
 
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ayushmishraaa09
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
Php Chapter 2 3 Training
Chris Chubb
 
Arrays in PHP
davidahaskins
 
4.1 PHP Arrays
Jalpesh Vasa
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Php functions
JIGAR MAKHIJA
 
Array String - Web Programming
Amirul Azhar
 
PHP array 1
Mudasir Syed
 
lab4_php
tutorialsruby
 
lab4_php
tutorialsruby
 

Recently uploaded (20)

PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Tally software_Introduction_Presentation
AditiBansal54083
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Executive Business Intelligence Dashboards
vandeslie24
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Ad

Array functions using php programming language.pptx