Skip to content

Instantly share code, notes, and snippets.

@fanaugen
Created June 26, 2013 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanaugen/5867913 to your computer and use it in GitHub Desktop.
Save fanaugen/5867913 to your computer and use it in GitHub Desktop.
previous content

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:

  1. String concatenation:

    echo "buy ".$groceries[0]." at the store";
    
  2. save in a variable beforehand:

    $first = $groceries[0];
    echo "buy $first at the store";
    
@fanaugen
Copy link
Author

This comment was previously published here but later revised because it's not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment