第10个逗号后的PHP换行符

我需要分割以下字符串:

333 ,351 ,359 ,360 ,370 ,371 ,385 ,492 ,512 ,514 ,528 ,539 ,546 ,628 ,630 ,634 ,636 ,702 ,706 ,709 ,710 ,715 ,718 ,719 ,763 ,770 ,803 ,822 ,823

分隔成几行,在最后一个第十个逗号后换行,如果有意义的话?

所以看起来像这样:

333 ,351 ,359 ,360 ,370 ,371 ,385 ,492 ,512 ,514 ,

528 ,539 ,546 ,628 ,630 ,634 ,636 ,702 ,706 ,709 ,

710 ,715 ,718 ,719 ,763 ,770 ,803 ,822 ,823

解决方法:

请检查注释以获取解释:-

 <?PHP
    error_reporting(E_ALL); // check if any error occur
    ini_set('display_errors',1); // display error
    $string = '333 ,351 ,359 ,360 ,370 ,371 ,385 ,492 ,512 ,514 ,528 ,539 ,546 ,628 ,630 ,634 ,636 ,702 ,706 ,709 ,710 ,715 ,718 ,719 ,763 ,770 ,803 ,822 ,823'; // original string
    echo $string; // echo original string
    $array = explode(',',$string); // explode string with comma to make it array
    echo "<pre/>";print_r($array); // print array
    $chunked_array = array_chunk($array,10); // chunk array to each 10 counts and make a multidimensional array
    $new_string = ''; // create a new empty string
    foreach ($chunked_array as $chunked_ar){ // iterate through multi-dimensional array 

      $new_string .= implode(',',$chunked_ar)."\n"; // convert each array to string and add new line and assign it to new string variable
    }
    echo $new_string; // echo new variable.
  ?>

输出:-https://eval.in/557389

注意:添加error_reporting代码(在<?PHP之后的前两行)始终是找出错误并加以解决的好方法.谢谢.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...