I need to change some array values in a 2-dimensional array for some cases. Sometimes the all values from an child array and sometimes only some values.
In this cases I should only change the variable $stamm
which $stamm2
.
This code is the statement of an if condition, where all relevant verbs for this changings is mentioned.
$verb
could be one over 25.000 french verbs. For this example you could use 'acheter'.
$array = array(
array('e', 'es', 'e', 'ons', 'ez', 'ent'), array('ais', 'ais', 'ait', 'ions', 'iez', 'aient'), array('ai', 'as', 'a', 'âmes', 'âtes', 'èrent'), array('erai', 'eras', 'era', 'erons', 'erez', 'eront'), array('e', 'es', 'e', 'ions', 'iez', 'ent'), array('asse', 'asses', 'ât', 'assions', 'assiez', 'assent'), array('erais', 'erais', 'erait', 'erions', 'eriez', 'eraient'), array('e', 'ons', 'ez'), array('XXX'), array('ant'));
My short old code:
$stamm = substr("$verb", 0, - 2); $stamm2 = substr_replace($stamm, '<u>è</u>', -2, 1); $array[0][0] = $array[0][2] = $array[4][0] = $array[4][2] = $array[7][0] = $stamm2.'e'; $array[0][1] = $array[4][1] = $stamm2.'es'; $array[0][5] = $array[4][5] = $stamm2.'ent';
My new improved code:
$stamm = substr("$verb", 0, - 2);
$stamm2 = substr_replace($stamm, '<u>è</u>', -2, 1);
$zeiten = array(0, 3, 4, 6, 7);
foreach($zeiten as $zeit) {
foreach($array[$zeit] as $person => $value) {
if ((($zeit == 0 || $zeit == 4) && !in_array($person,array(3,4))) || ($zeit == 3 || $zeit == 6) || ($zeit == 7 && $person==0))
$array[$zeit][$person] = str_replace($stamm, $stamm2, $value);
}
}
Is this the the new code the best solution? Is it possible to improve the if condition?
$array
,$stamm
and$stamm2
. – Nobody Jun 10 at 8:53$array
. To make it more clear: Preferably your code should be runnable as is. As far as I can see you should provide example values for$array
and$verb
and would be fine. – Nobody Jun 10 at 9:18$array
and$stamm
. The code is workung for both versions. – Grischa Jun 10 at 9:25$verb
and the overall description of what you are trying to do. My assumption is: You are trying to build a function that gives all possible inflections of a given verb according to french language. Is that right? – Nobody Jun 10 at 9:31