0

I wanted to ask, how can i modify array values when doing foreach - in my example, i want to add to every element, but this code produces error.

foreach ($logo as &$value) {
                $value = '<div>' . $value . '</div>';
                debug ($value);
            }
            ?>

and the error: Notice (8): Array to string conversion

I'm using php 5.6

Thanks for reply.

1
  • 1
    print $logo array before foreach as per understanding this is multidimensional array Commented Jun 22, 2016 at 8:10

1 Answer 1

1

I use

$serviceMe = ""; //OR use beginning html
foreach( $tmp as $t ) $serviceMe .= '<tr>' . $t . '</tr>';
$serviceMe .= ""; // Rest of the needed html

Make absolutely sure what type of is your $value. Is it integer,float,string,object,array... etc

I think your error comes from trying to convert array to string without proper handling.

$array = new array(
    'key'    => $value,
    'key2'    => $value2,
    'key3'    => $value3,
);
$string = "" . $array; //throws error!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.