 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
01-24-2008, 09:56 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
A little challange for you all
Well, hopefully it will be a challange
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
|
|
|
01-24-2008, 10:06 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
01-24-2008, 10:16 PM
|
#3 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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;
?>
__________________
no signature set
|
|
|
|
01-24-2008, 10:17 PM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
You get half a cookie for keeping quiet
Alan
|
|
|
01-24-2008, 10:18 PM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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. 
|
|
|
|
01-24-2008, 10:19 PM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
01-24-2008, 10:21 PM
|
#7 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
Quote:
Originally Posted by Alan @ CIT
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;
?>
__________________
no signature set
|
|
|
|
01-24-2008, 10:27 PM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
Another good attempt, but this time you are echo'ing a variable named 'output', not '999'
Keep trying though! That cookies waiting!
Alan
|
|
|
01-24-2008, 10:30 PM
|
#9 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
Quote:
Originally Posted by Alan @ CIT
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?
__________________
no signature set
|
|
|
|
01-24-2008, 10:32 PM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
01-24-2008, 10:35 PM
|
#11 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
Quote:
Originally Posted by Alan @ CIT
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};
?>
__________________
no signature set
|
|
|
|
01-24-2008, 10:40 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
01-24-2008, 10:52 PM
|
#13 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Yay, how's that cookie taste sarmenhb?
Time for some more little challenges methinks!
|
|
|
|
01-24-2008, 11:04 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
I suck D: (chars)
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-24-2008, 11:10 PM
|
#15 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
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
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?

|
|
|
01-24-2008, 11:11 PM
|
#16 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Rendair
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 
|
User created challeneges, >:D I know what I'd make hehe >:D
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-25-2008, 12:27 AM
|
#17 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
|
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
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?
__________________
Not quite a n00b...
|
|
|
|
01-25-2008, 12:39 AM
|
#18 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
A sponge
Temples will fall, and mountains will crumble no man can survive it's call, what am I?
|
|
|
|
01-25-2008, 12:56 AM
|
#19 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by TlcAndres
A sponge
Temples will fall, and mountains will crumble now man can survive it's call, what am I?
|
God ( not religious >.> )
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-25-2008, 12:58 AM
|
#20 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
nay, though I can see where that answer would fill the perquisite answers.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|