php example code : array_slice function in php - slice the array upto an specified length
array-slice-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>
<title>php example code : array_slice function in php - slice the array upto an specified length</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="php example code : array_slice function in php - slice the array upto an specified length">
<meta name="keywords" content="php, example, code, array, function, array_slice">
<meta name="description" content="php example code : array_slice function in php - slice the array upto an specified length">
</head>
<body>
<h3>php example code : array_slice function in php - slice the array upto an specified length</h3>
<?php
/*
------------------------------------------------
let us make an array with some keys and values
------------------------------------------------
*/
$myArray = array("key1"=>"value1","key2"=>"value2","key3"=>"value3");
echo "<p style='background:#aaa; color:red;'>Output of myArray</p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
/*
-------------------------------------------------------------------------------
we want to slice up the array up to 2 elements by using array_slice function
-------------------------------------------------------------------------------
*/
$finalArray = array_slice($myArray, 0, 2);
echo "<p style='background:#ccc; color:red;'>Output of finalArray using array_slice function</p>";
echo "<pre>";
print_r($finalArray);
echo "</pre>";
?>
</body>
</html>

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