TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   A little challange for you all (http://www.talkphp.com/general/2085-little-challange-you-all.html)

Alan @ CIT 01-24-2008 09:56 PM

A little challange for you all
 
Well, hopefully it will be a challange :-D

Here's what you have to do:

PHP Code:

<?php

$999 'Hello';
echo $
999;

Now, in its current state, that code won't work. Your job is to get it working :-)

Rules: The variable name must be 999 and it must contain the string 'Hello' and you must echo the variable to display the string.

---> First one to post a working answer wins a cookie! :-)

Good luck all!

Alan

Wildhoney 01-24-2008 10:06 PM

I know, I know! But to keep it a challenge I won't reveal :-) ! I saw this in a book I have a while ago - quite crafty, though I certainly wouldn't recommend naming your variables like this.

sarmenhb 01-24-2008 10:16 PM

BINGO!!!!

<?php

$test = array('9','9','9');

$test[0] = "he";
$test[1] = "ll";
$test[2] = "o";
$output = "$test[0]$test[1]$test[2]";



echo $output;

?>

Alan @ CIT 01-24-2008 10:17 PM

You get half a cookie for keeping quiet :-D

Alan

Salathe 01-24-2008 10:18 PM

I blogged about this sort of thing not very long ago, would it be rude to claim the cookie before many others take a stab at it? Thinking about it, lets be sporting. If you can think up any weird and wacky solutions (sarmenhb had a good stab at it!), they might not be awarded a cookie but it'll be fun anyway. :-P

Alan @ CIT 01-24-2008 10:19 PM

Good attempt sarmenhb but there isn't a variable named 999 which contains the string 'Hello' - you have a variable called $test containing an array of 'Hello' parts :-)

Good thinking though!

Alan

sarmenhb 01-24-2008 10:21 PM

Quote:

Originally Posted by Alan @ CIT (Post 9560)
Good attempt sarmenhb but there isn't a variable named 999 which contains the string 'Hello' - you have a variable called $test containing an array of 'Hello' parts :-)

Good thinking though!

Alan


BINGO!!!

BINGO!!!!

<?php

$test = array('9','9','9');

$test[0] = "he";
$test[1] = "ll";
$test[2] = "o";
$output = "$test[0]$test[1]$test[2]";



echo $output;

?>

Alan @ CIT 01-24-2008 10:27 PM

Another good attempt, but this time you are echo'ing a variable named 'output', not '999' :-)

Keep trying though! That cookies waiting!

Alan

sarmenhb 01-24-2008 10:30 PM

Quote:

Originally Posted by Alan @ CIT (Post 9562)
Another good attempt, but this time you are echo'ing a variable named 'output', not '999' :-)

Keep trying though! That cookies waiting!

Alan

lol you mentioned $output only not $test so then i can just remove $output and echo out the array.

does that work?

Alan @ CIT 01-24-2008 10:32 PM

Afraid not :-) You need to have a variable named '999', that contain the string 'Hello' (string, not array), and then echo that variable to display the string 'Hello' :-)

Alan

sarmenhb 01-24-2008 10:35 PM

Quote:

Originally Posted by Alan @ CIT (Post 9564)
Afraid not :-) You need to have a variable named '999', that contain the string 'Hello' (string, not array), and then echo that variable to display the string 'Hello' :-)

Alan

ROFL

Code:

<?php

${999} = "hello";

echo ${999};
?>


Alan @ CIT 01-24-2008 10:40 PM

ok, turned out not to be such a challange after all :D Sarmenhb wins the Cookie!

An alternative way (and the way I was thinking of when I wrote the question is to use variable variables :)

Eg:

PHP Code:

<?php

$badName 
'999';
$
$badName 'Hello';

echo ${
'999'};

Enjoy your cookie!

Alan

Salathe 01-24-2008 10:52 PM

Yay, how's that cookie taste sarmenhb? :-)

Time for some more little challenges methinks!

Orc 01-24-2008 11:04 PM

I suck D: (chars)

Rendair 01-24-2008 11:10 PM

I really like this idea of challenges lol i think should have a area for these kind of challenges that the mods and admins can set maybe come up with some kind of point system :-P

Heres one for ya

What can run but never walks, has a mouth but never talks, has a head but never weeps, has a bed but never sleeps?

:-D

Orc 01-24-2008 11:11 PM

Quote:

Originally Posted by Rendair (Post 9573)
I really like this idea of challenges lol i think should have a area for these kind of challenges that the mods and admins can set maybe come up with some kind of point system :-P

User created challeneges, >:D I know what I'd make hehe >:D

CMellor 01-25-2008 12:27 AM

Quote:

What can run but never walks, has a mouth but never talks, has a head but never weeps, has a bed but never sleeps?
A river :-P

I have holes on the top and bottom. I have holes on my left and on my right. And I have holes in the middle, yet I still hold water. What am I?

TlcAndres 01-25-2008 12:39 AM

A sponge


Temples will fall, and mountains will crumble no man can survive it's call, what am I?

Orc 01-25-2008 12:56 AM

Quote:

Originally Posted by TlcAndres (Post 9591)
A sponge


Temples will fall, and mountains will crumble now man can survive it's call, what am I?

God ( not religious >.> )

TlcAndres 01-25-2008 12:58 AM

nay, though I can see where that answer would fill the perquisite answers.


All times are GMT. The time now is 12:23 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0