Tomislav Nikolic Tomislav Nikolic - 11 days ago 6
PHP Question

Multidimensional array to string using implode

Alright so for some reason even with implode in place I am getting an error saying Array to string Conversion on this line

echo implode($weather['list'][0]['weather']);



Notice: Array to string conversion in

Answer

I got this notice while trying to implode an array with inner dimensions:

$arrayWithInnerDimensions = [
    'first_dimension' => [
            'a',
            'b' => [1,2],
            'c',
        ]
    ];

echo implode($arrayWithInnerDimensions['first_dimension']); //notice

echo "\n\n";

$arrayWithoutInnerDimensions = [
    'first_dimension' => [
            'a',
            'b' => 'd',
            'c',
        ]
    ];

echo implode($arrayWithoutInnerDimensions['first_dimension']); //ok