drwghu6386 2017-11-29 17:01
浏览 81
已采纳

将字符串放在数组中的每个数组之间 - PHP

Lets say I have a text file with 9 sentences (it could be more! this is just an example) , then i read that file in my php and split it every 3 sentence and store it in a variable so it result in this array:

$table = array(
   array(
        'text number 1',
        'text number 2',
        'text number 3'
    ),
   array(
        'text number 4',
        'text number 5',
        'text number 6'
    ),
   array(
        'text number 7',
        'text number 8',
        'text number 9'
    ),
 );

and then I want to add this string ('[br/]') between every array inside so it looks :

$table = array(
   array(
        'text number 1',
        'text number 2',
        'text number 3'
    ),

   '[br/]',  // <<< ---- the string here

   array(
        'text number 4',
        'text number 5',
        'text number 6'
    ),

   '[br/]',  // <<< ---- the string here

   array(
        'text number 7',
        'text number 8',
        'text number 9'
    ),
);

I've already tried this:

 foreach( $table as $key => $row )
  $output[] = array_push($row, "[br /]");

Which logically should have worked, but it hasn't.

Any help would be appreciated.

  • 写回答

3条回答 默认 最新

  • douxiongye5779 2017-11-29 17:08
    关注

    You can just remap the array by using something like this:

    $result = [];
    foreach($table as $item) {
        $result[] = $item;
        $result[] = '[br/]';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题