1

I am tried to add the same string to every array value. I tried to use array_walk() like I read it on this answer.

But I get: Notice: Array to string conversion

I have also tried to use array_map(), but I get same error notice.

working code

if ($voice->getValue() === Voice::Passive) {
    array_walk($aller_form, function(&$value, $key) { $value .= ' être'; });
    $aller_form = [
        Mood::Indicatif => [
            Tense::Futur_compose => [
                Person::FirstPersonSingular => 'vais être',
                Person::SecondPersonSingular => 'vas être',
                Person::ThirdPersonSingular => 'va être',
                Person::FirstPersonPlural => 'allons être',
                Person::SecondPersonPlural => 'allez être',
                Person::ThirdPersonPlural => 'vont être'
            ]
        ]
    ];
}  
return $aller_form[$mood->getValue()][$tense->getValue()][$person->getValue()];

not working code

if ($voice->getValue() === Voice::Passive) {
    array_walk($aller_form, function(&$value, $key) { $value .= ' être'; });            
} 
return $aller_form[$mood->getValue()][$tense->getValue()][$person->getValue()];

EDIT:

The complete error log:

Notice: Array to string conversion in on line 2

Warning: Illegal string offset 'futur_compose' on line 4

Warning: Illegal string offset 'firstPersonSingular' on line 4

(I see 6 times this three error lines for every Person once)

Community
  • 1
  • 1
Grischa
  • 70
  • 8
  • 26
  • What is the output of: `print_r($aller_form);`? Also your working and not working code line are exactly the same – Rizier123 Apr 10 '16 at 10:24
  • SHOW us the FULL error message and identify the exact line of code in your script that is identified on the error message ( theres a line number in the error ) It would also be useful to know what `$voise` is and what `VOICE::` and the 2 data types in the comparision, but I guess if you look for this information **the answer to the question will become obvious** – RiggsFolly Apr 10 '16 at 10:26
  • @Rizier123 The output of `print_r($aller_form);` is `Array ( [0] => vais [1] => vas [2] => va [3] => allons [4] => allez [5] => vont )` – Grischa Apr 10 '16 at 10:37

0 Answers0