douyin2435 2015-06-05 16:04
浏览 31
已采纳

将str_replace与substr结合使用

My conjugation script combines $stamm(2) with all endings from the 2 dimensional array called $array.

part of a foreach loop

$array[3][0] = str_replace($stamm, $stamm2.'o</u>', $value). $red_slash.str_replace($stamm, $stamm2.'ié</u>', $value);

for example

$stamm2='begin';
$stamm3='begin2';
$array[3][0] = array ('irai','iras','ira','irons','irez','iront');

Now I have a case with 2 different regular verb forms with different roots ($stamm2 and $stamm3) but also different endings ($array[3][0]). In the second option should be everytime the first ending letter i deleted.

How is it possible to add substr function or something else what would help me for this part?

str_replace($stamm, $stamm2.'ié</u>', $value);

output: (without the adding the strings o/ié to $stamm2/$stamm3)

beginirai / begin2irai
beginiras / begin2iras
beginira / begin2ira
beginirons / begin2irons
beginirez / begin2irez
beginiront / begin2iront

desired output: (without the adding the strings o/ié to $stamm2/$stamm3)

beginirai / begin2rai
beginiras / begin2ras
beginira / begin2ra
beginirons / begin2rons
beginirez / begin2rez
beginiront / begin2ront
  • 写回答

1条回答 默认 最新

  • dongqiao1158 2015-06-05 16:34
    关注

    As far as I understood from your desired output, I wrote the following code: (Let me know if I didn't understand you well in the comments section)

    $prefix1 = 'begin';
    $prefix2 = 'begin2';
    
    $inputArr = array('irai', 'iras', 'ira', 'irons', 'irez', 'iront');
    $outputArr1 = array();
    $outputArr2 = array();
    
    foreach($inputArr as $input){
     $outputArr1[] = $prefix1 . $input; //for instance: beginirai
     $outputArr2[] = $prefix2 . substr($input, 1); //for instance: begin2rai
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式