php example code : array_chunk function in php - splits the array into several arrays
array-chunk-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>php example code : array_chunk function in php - splits the array into several arrays</title>
</head>
<body>
<h3>php example code : array_chunk function in php - splits the array into several arrays</h3>
<?php
/*
--------------------------------------------------------
let us make an array and splits it into several arrays
by using php array_chunk function
--------------------------------------------------------
*/
$myArray = array('i', 'am', 'an array', 'to test array_chunk function', 'i think i m ok');
echo "<p style='background:#ccc; color:red;'>Output of my array with structure: </p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
echo "<pre>";
var_dump($myArray);
echo "</pre>";
$splitedArraySize = 3;
/*
--------------------------------------------------------
by defining $splitedArraySize we can set the number of
members in the new array(s)
--------------------------------------------------------
*/
$newArray = array_chunk($myArray, $splitedArraySize);
echo "<p style='background:yellow; color:black;'>Output of my array with structure using array_chunk function: </p>";
echo "<pre>";
print_r($newArray);
echo "</pre>";
echo "<pre>";
var_dump($newArray);
echo "</pre>";
?>
</body>
</html>

No comments:
Post a Comment
leave your comments here..