So i have a problem with taking an array and looping through the values and outputing with a foreach statement.
code
<?php
$example = array("test" => "hello world" );
foreach ($example as $arr) {
printf("<p>what do you have to say for yourself?</p><p>%s!</p>",$arr["test"]);
}
?>
hoping to get the output:
what do you have to say for yourself?
hello world!
Instead get
what do you have to say for yourself?
h!
why just the single character?
Any help would be great
thanks
Your foreach loop is already going through the values of the array, so don’t reference the value again using the key:
From your other example in the comments, you would not be able to use a loop because the placements are very specific. Instead reference each value specifically without a loop: