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 trial

PHP PHP Basics Unit Converter Integers

Sufiyaan Haroon
seal-mask
.a{fill-rule:evenodd;}techdegree
Sufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 Points

What is a string?!?

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

Just a quick run-down of the most common variable types;

  • A 'Boolean' is a True/False Value, making them the easiest 'Yes/No' type control-value.
  • An 'Int' is an Integer Value, or a Whole Number Value, so any number without a comma.
  • A 'Float' is a Floating Value Number, meaning they have a certain amount of numbers after the comma (the amount of values after the comma varies a bit).
  • A 'String' is a Text Value, so a single word or line of text.

What you can do with the different variables obviously vary; you can't multiply a String (Text) with a Boolean (True/False), for example.

2 Answers

Simon Coates
Simon Coates
28,694 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

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