How------------the PHP algorithm print out the image below

Source: Internet
Author: User

I saw it occasionally. Then print it out in PHP.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvegluz2ppz29uz3np/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

There are two ways to resolve this issue:

Method One: According to the graph analysis of the graph is a two-dimensional array, two-dimensional array can solve such problems, 6 rows is 6 arrays, each row represents the array of how many elements. Know the number of elements in each array. Can you tell which elements are in the array?

function array_chunk_vertical ($arr, $colun) {    $arr _length = count ($arr);    $parem = Floor ($arr _length/$colun);    $pare = $arr _length% $colun;    $ar = Array ();    for ($i = 0; $i < $colun; $i + +) {        $par = $i = = $colun-1? 1:5;        $ar [] = $par;    }    $newarray = Array ();    foreach ($ar as $value) {for        ($i = 0; $i < $value; $i + +) {            $newarray [$i] = Array_shift ($arr);        }    }    return $newarray;} $arr = Range (1, +), $data = Array_chunk_vertical ($arr, 7), foreach ($data as $value) {    foreach ($value as $va) {        printf (' [%2s] ', $va);    }    echo "<br/>";}

Method Two: such as code. An empty array of size is given first. Fills the element in an empty array.

Detailed methods such as the following:

<? 

PHP function array_chunk_vertical ($input, $size, $preserve _keys = False, $size _is_horizontal = False) {$chunk s = Array (); if ($size _is_horizontal) {$chunk _count = ceil (count ($input)/$size); } else {$chunk _count = $size; } for ($chunk _index = 0; $chunk _index < $chunk _count; $chunk _index++) {$chunks [] = array (); } $chunk _index = 0; foreach ($input as $key = + $value) {if ($preserve _keys) {$chunks [$chunk _index][$key] = $value; } else {$chunks [$chunk _index][] = $value; if (+ + $chunk _index = = $chunk _count) {$chunk _index = 0; }} return $chunks;} $data =range (1,31), $newdata =array_chunk_vertical ($data, 6), foreach ($newdata as $root) {foreach ($root as $val) {p rintf (' [%2s] ', $val); } echo "<br/>";}


How does the PHP algorithm------------print out

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.