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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化