mardi 25 octobre 2016

string mutation with rtrim in php

I want to have a certain scheme for my input so that I should get something like v- but instead I just get -. My code :

$name = array("mobassa","karassp");

for($i=0;$i<count($name);$i++)
{

$lang = array("k","p");

$hello = substr($name[$i],-1);

    if (in_array($hello,$lang)){
        $moe = rtrim("-",$hello);

    }



    else {$moe = rtrim("v",$hello);}

}

print $moe;

How do I have to change the if/else condition so that I get the desired output?

Aucun commentaire:

Enregistrer un commentaire