Split an array into chunks of two and preserve the original keys in PHP

Description

The following code shows how to split an array into chunks of two and preserve the original keys.

Example


/*  w  ww  .j  av  a  2  s.  c  om*/
<?php
   $age=array("XML"=>"35","HTML"=>"37","CSS"=>"43","Java"=>"50");
   print_r(array_chunk($age,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