Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Unit Converter Integers

What is a string?!?

I don't know what is a string in the programming language. Can someone please tell me.

2 Answers

Simon Coates
Simon Coates
28,692 Points

At a basic level, it's a sequence of characters (eg "this is a string literal"). see http://php.net/manual/en/language.types.string.php

but what is its purpose?

Simon Coates
Simon Coates
28,692 Points

to store textual data. You can get textual data from users, process it, store it, and output textual data to users.

String is sequence of characters

  • $fruit = 'Apple';
  • $vegetable = 'tomato';

For example you want to display it into list what you have bought

<ul>
   <li><?php echo $fruit; ></li>
   <li><?php echo $vegetable; ></li>
</ul>

In the real world solutions you will probably use some templating system.

If you are curious look at:

The first one is often used with symfony.

The second one with laravel and the last one with nette.

If you ask why to use f.e. twig, let me rewrite my example it would look like this:

<ul> 
   <li>{{ fruit }}</li>
   <li>{{ vegetable }}</li>
</ul>

It has specific syntax which helps you write more concise and readable code