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

将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

图片转代码服务由CSDN问答提供 功能建议

我的共轭脚本将 $ stamm(2)与来自二维数组的所有结尾相结合 名为 $ array

foreach循环的一部分

  $ array [3] [0] =  str_replace($ stamm,$ stamm2.'o&lt; / u&gt;',$ value)。  $ red_slash.str_replace($ stamm,$stamm2.'ié&lt; / u&gt;',$ value); 
   
 
 

例如

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

现在我有一个案例,其中有两个不同的常规动词形式,具有不同的根( $ stamm2 $ stamm3 )但也有不同的结局( $ array [3] [0] )。 第二个选项应该是每次删除的第一个结束字母。< / p>

如何添加substr函数或其他什么对我有用的东西呢?

str_replace($ stamm,$ stamm2 .'ié&lt; / u&gt;',$ value);

输出:(没有将字符串o /ié添加到 $ stamm2 / $ stamm3

  beginirai / begin2irai 
beginiras / begin2iras 
beginira / begin2ira 
beginirons / begin2irons 
beginginz / begin2irez 
beginiront / begin2iront 
 <  / code>  
 
 

所需的输出:(没有插件 g字符串o /ié到 $ 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
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题