Split an array into chunks of two in PHP

Description

The following code shows how to split an array into chunks of two.

Example


// ww w.  j  a v  a 2  s  .  co  m
<?php
    
    //Split an array into chunks of two
    $myValue=array("XML","CSS","HTML","Java","Javascript","MySQL");
    print_r(array_chunk($myValue,2));
    
    $input_array = array('a', 'b', 'c', 'd', 'e');
    print_r(array_chunk($input_array, 2));
    print_r(array_chunk($input_array, 3));
    print_r(array_chunk($input_array, 2, true));    
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone