array_chunk($var,2);

print_r(array_chunk($var,2));

array_chunk(); function is used for divide the main array into coder requirement. According to practical thinking you can imagine there is a variable and this is array which has total ten values. If you want to print couple of values in per chunk you have to code array_chunk($var,2); function into print_r(); function. Then you will see there will be create five chunk and each chunk is containing two values. But if there would be total 11 values you would get six chunks and in the final chunk will contain the rest of value that means the last chunk will contain only one value. An example coding is given below.

<?php
    $cnk = array("value1","Value2","Value3","Value4","Value5","Value6","Value7");
    echo "<pre>";
    print_r(array_chunk($cnk, 2));
?>

Comments

Popular posts from this blog

WP register_post_type() with custom CMB2 meta box

Git post receive setup at server for git push to the production from local machine