Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 PointsWhat is a string?!?
I don't know what is a string in the programming language. Can someone please tell me.
2 Answers
Simon Coates
28,694 PointsAt 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
Sufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 Pointsbut what is its purpose?
Simon Coates
28,694 Pointsto store textual data. You can get textual data from users, process it, store it, and output textual data to users.
Tomas Svojanovsky
26,680 PointsString 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
Michael Kristensen
Full Stack JavaScript Techdegree Graduate 26,251 PointsMichael Kristensen
Full Stack JavaScript Techdegree Graduate 26,251 PointsJust a quick run-down of the most common variable types;
What you can do with the different variables obviously vary; you can't multiply a String (Text) with a Boolean (True/False), for example.