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

Create two variables called $a and $b. Set $a to 100 and $b to 101. Then write some logic to swap the values of the two

I'm really having an issue with this question, someone please tell me how to properly write this code. I'm in a programming fundamentals class, and I have no Idea how to do this, and I need a PHP pro, who knows their stuff. Thank you!

4 Answers

Julie Dowler
Julie Dowler
7,851 Points

Sekoyya Little: I think what you're saying is you're in a class that teaches general programming concepts, but they have told you nothing about PHP syntax. Here's how to write it in PHP (assuming they don't want you to create functions). $a = 100; $b = 101; $temp = $a; $a = $b; $b = $temp; if ($a >= $b) { echo "a is not smaller than b"; } else { echo "a is smaller than b"; }

Thank you Julie for giving me the best answer!

This is the entire question here :

Create two variables called $a and $b. Set $a to 100 and $b to 101. Then write some logic to swap the values of the two variables. You can use a temp variable called $temp to store one of the variables when you are swapping the value of the variable. Once the swapping is done, make sure you destroy $temp.

Then

Write an if check to see if to see if $a is bigger or equals to $b, if it is bigger or equals then print “a is not smaller than b”, else print “a is smaller than b”

You have the answer after the then section. you write a conditional statement and then echo out the string provided. if $a is bigger or equals $b.

If you are still fuzzy on the syntax of this, I'd advise on watching the video that discusses a conditional statement.

Could you please write the code out for me, and then screen shot it? Please! :)

No, I'm not writing out the code for you. It kinda goes against learning how to code.

Having said that you wrote out the sudo code like so...

if $a is greater or equal to $b: echo "a is not smaller than b" else: echo "a is smaller than b"

writing something like this is a foundational level operation. If you do not know how to write this you really should watch the video on how to write a conditional statement. That one line above is the answer to the question, turn it into PHP, and you'll be good to go.

Your no help Jacob...