echo "Please pick up the following from the store: $groceries[0]";
This isn't going to work by the way: inserting a variable's value into a string "like $x this"
only works with a simple variable such as $x
– for array elements you have two other options:
-
String concatenation:
echo "buy ".$groceries[0]." at the store";
-
save in a variable beforehand:
$first = $groceries[0]; echo "buy $first at the store";
This comment was previously published here but later revised because it's not correct.