Mixed Variable Types Challenge and Quiz

phpBB3 and MOD challenges setup by the staff to test and challenge your phpBB3 coding skills.

Mixed Variable Types Challenge and Quiz

Postby Highway of Life » 28 Mar 2007, 15:07

Okay, here is somewhat of a simple challenge for EVERYBODY.
Even if you are fairly knowledgeable in PHP, go ahead and take this challenge.
Just be sure to post your answers inside of spoiler tags so that it does not spoil it for anybody else.
Copy the following and paste it into a text file, then fill out the answers.
NO CHEATING!! Wink it?s on you of course, I can?t verify if you?re cheating or not. Wink

Here is the drill.
Each of these variables has a variable type.
Fill in the main variable type, and you can choose 1 or 0 for each of the is_<condition> statements.
If you don?t know what one or any of the is_<condition>'s are, just leave a '?' next to it.
After a fair number of people have posted their results, I?ll post the answers, so get em' in quick! Tongue
Have fun!!
Code: Select all
$var = 0;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = 1;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = ?0?;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = ?1?;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = 10;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = ?10?;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = 1.2;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = ?1.2?;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = ?true?;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = false;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = array(
   '0'   => foo,
   '1'   => bar,
);
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = new test_parent();
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = NULL;
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:

----
$var = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
type:
is_array:
is_bool:
is_double:
is_float:
is_int:
is_null:
is_numeric:
is_object:
is_resource:
is_scalar:
is_string:
Last edited by Highway of Life on 30 Mar 2007, 21:49, edited 2 times in total.
Reason: more readable now...
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: Mixed Variable Types Challenge and Quiz

Postby Deatzo Seol » 30 Mar 2007, 17:25

Spoiler:
Code: Select all
$var = array(
    [0] => 'foo',
    [1] => 'bar',
);

type:
is_array: 1
is_bool: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0
----
$var = 1;
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0
----
$var = 1.2;
type:
is_array: 0
is_bool: 0
is_float: 1
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0
----
$var = '1.2';
type:
is_array: 0
is_bool: 0
is_float: 1
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1
----
$var = '1';
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1
----
$var = 0;
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0
----
$var = '0';
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1
----
$var = 'hello world';
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1
----
$var = true;
type:
is_array: 0
is_bool: 1
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0
----
$var = false;
type: boolean --> ???? :confused:
----
$var = 'true';
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1
----
$var = 'false';
type: boolean --> ????? :confused:
----
$var = NULL;
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 1
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0
----
$var = 'NULL';
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 1
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0
----
$foo->bar();
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 1
is_resource: 1
is_scalar: 0
is_string: 0
----
$var = mysql_query('SELECT * FROM foo_table');
type:
is_array: 0
is_bool: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 1
is_scalar: 0
is_string: 0

I hope this is correct, as my knowledge of PHP is not perfect ... Glare
One should never increase, beyond what is necessary, the numbers required to explain anything.
Deatzo Seol
Cadet I
Cadet I
 
Posts: 17
Joined: 19 Jul 2006, 03:27
Location: Assimilated
Gender: Male

Re: Mixed Variable Types Challenge and Quiz

Postby Highway of Life » 30 Mar 2007, 22:13

Nice job Deatzo!! Good

Excluding the two problems that were skipped due to my mistake Doh , here are the results.
8 out of 14 problems correct. 57%
132 out of a possible 140 tests correct. 94%

Overall score: 76%

I?ve cleaned up my test text a bit and added is_double as an 11th test.
Also, for all future results, be sure to specify the primary type of variable in the type: field. Wink
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: Mixed Variable Types Challenge and Quiz

Postby Sniper_E » 30 Mar 2007, 22:19

I so don't understand what you are doing. But please don't explain.

Good job Deatzo Seol!
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
User avatar
Sniper_E    
STG Jedi Master
STG Jedi Master
 
Posts: 7003
Joined: 31 May 2006, 06:29
Location: Shreveport, LA
Favorite Team: The STG Team
Gender: Male
phpBB Knowledge: 6

Re: Mixed Variable Types Challenge and Quiz

Postby CorniI » 26 Apr 2007, 08:40

Let 's try it out :P
Spoiler:
$var = 0;
type:
is_array: 0
is_bool: 0
is_double: 1
is_float: 1
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = 1;
type:
is_array: 0
is_bool: 0
is_double: 1
is_float: 1
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?0?;
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?1?;
type:

is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = 10;
type:
is_array: 0
is_bool: 0
is_double: 1
is_float: 1
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?10?;
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource:0
is_scalar: 1
is_string: 1

----
$var = 1.2;
type:
is_array: 0
is_bool: 0
is_double: 1
is_float: 1
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?1.2?;
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = ?true?;
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = false;
type:
is_array: 0
is_bool: 1
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = array(
'0' => foo,
'1' => bar,
);
type:
is_array: 1
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0

----
$var = new test_parent();
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 1
is_resource: 0
is_scalar: 0
is_string: 0

----
$var = NULL;
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 1
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0

----
$var = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
type:
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 1
is_scalar: 0
is_string: 0

A bit of Sisyphus Work :banghead: But pls look at it :)
CorniI
CorniI
Crewman
Crewman
 
Posts: 6
Joined: 17 Apr 2007, 08:24
Location: Germany
Favorite Team: Sport kills!
Gender: Male
phpBB Knowledge: 6

Re: Mixed Variable Types Challenge and Quiz

Postby Sniper_E » 26 Apr 2007, 11:17

What exactly are you doing here? Are you running a query on these different $vars and seeing if they are is_this? or is_not_this?
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
User avatar
Sniper_E    
STG Jedi Master
STG Jedi Master
 
Posts: 7003
Joined: 31 May 2006, 06:29
Location: Shreveport, LA
Favorite Team: The STG Team
Gender: Male
phpBB Knowledge: 6

Re: Mixed Variable Types Challenge and Quiz

Postby Highway of Life » 26 Apr 2007, 11:38

Sniper_E wrote:What exactly are you doing here? Are you running a query on these different $vars and seeing if they are is_this? or is_not_this?
As a standard, it?s a quiz to see if you know what they are.
Part of coding is knowing what kind of variables you are working with.

However, you can verify your answer(s) by creating a simple script and checking those.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: Mixed Variable Types Challenge and Quiz

Postby blackbeltboy47 » 18 May 2007, 21:02

I don't know how well I will do but here it goes...

Spoiler:
$var = 0;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:0

----
$var = 1;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:0

----
$var = ?0?;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = ?1?;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = 10;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:0

----
$var = ?10?;
type: integer
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = 1.2;
type: float
is_array:0
is_bool:0
is_double:0
is_float:1
is_int:0
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:0

----
$var = ?1.2?;
type: float
is_array:0
is_bool:0
is_double:0
is_float:1
is_int:0
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = ?true?;
type: boolean
is_array:0
is_bool:1
is_double:0
is_float:0
is_int:0
is_null:0
is_numeric:0
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = false;
type: boolean
is_array:0
is_bool:1
is_double:0
is_float:0
is_int:0
is_null:0
is_numeric:0
is_object:0
is_resource:0
is_scalar:0
is_string:0

----
$var = array(
'0' => foo,
'1' => bar,
);
type: array
is_array:1
is_bool:0
is_double:1
is_float:0
is_int:1
is_null:0
is_numeric:1
is_object:0
is_resource:0
is_scalar:1
is_string:1

----
$var = new test_parent();
type: resource
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:0
is_null:0
is_numeric:0
is_object:0
is_resource:1
is_scalar:0
is_string:0

----
$var = NULL;
type: null
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:0
is_null:1
is_numeric:0
is_object:0
is_resource:0
is_scalar:0
is_string:0

----
$var = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
type: resource
is_array:0
is_bool:0
is_double:0
is_float:0
is_int:0
is_null:0
is_numeric:0
is_object:0
is_resource:1
is_scalar:1
is_string:1


Again I don't know php very well, I completely guessed on the types. But i do want to learn.
-blackbeltboy47
User avatar
blackbeltboy47
Cadet IV
Cadet IV
 
Posts: 40
Joined: 29 Jan 2007, 17:20
Gender: Male

Re: Mixed Variable Types Challenge and Quiz

Postby iWisdom » 10 Jul 2007, 20:16

Oh dear...
Spoiler:
Code: Select all
$var = 0;
type: int
is_array: 0
is_bool:  1
is_double: 1
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object:  0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = 1;
type: int
is_array: 0
is_bool: 1
is_double: 1
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?0?;
type: string
is_array: 0
is_bool: 0
is_double: 1
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = ?1?;
type: string
is_array: 0
is_bool: 1
is_double: 0
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = 10;
type: int
is_array: 0
is_bool: 0
is_double: 1
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = ?10?;
type: string
is_array: 0
is_bool: 0
is_double: 1
is_float: 0
is_int: 1
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = 1.2;
type: float
is_array: 0
is_bool: 0
is_double: 0
is_float: 1
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = ?1.2?;
type: string
is_array: 0
is_bool: 0
is_double: 0
is_float: 1
is_int: 0
is_null: 0
is_numeric: 1
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = ?true?;
type: string
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 1

----
$var = false;
type: bool
is_array: 0
is_bool: 1
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 1
is_string: 0

----
$var = array(
   '0'   => foo,
   '1'   => bar,
);
type: array
is_array: 1
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 1

----
$var = new test_parent();
type: object
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 1
is_resource: 0
is_scalar: 0
is_string: 0

----
$var = NULL;
type: null
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 0
is_scalar: 0
is_string: 0

----
$var = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
type: resource
is_array: 0
is_bool: 0
is_double: 0
is_float: 0
is_int: 0
is_null: 0
is_numeric: 0
is_object: 0
is_resource: 1
is_scalar: 1
is_string: 0
Something tells me I failed...
iWisdom    
phpBB Team Member
phpBB Team Member
 
Posts: 58
Joined: 10 Jul 2007, 20:01
Gender: Male
phpBB Knowledge: 10

Re: Mixed Variable Types Challenge and Quiz

Postby Highway of Life » 11 Jul 2007, 13:32

iWisdom scores:

Spoiler:
Code: Select all
$var = 0;
type: integer
9 out of a possible 11 are correct for a score of 81%
----
$var = 1;
type: integer
9 out of a possible 11 are correct for a score of 81%
----
$var = "0";
type: string
9 out of a possible 11 are correct for a score of 81%
----
$var = "1";
type: string
9 out of a possible 11 are correct for a score of 81%
----
$var = 10;
type: integer
9 out of a possible 11 are correct for a score of 81%
----
$var = 1.2;
type: double
10 out of a possible 11 are correct for a score of 90%
----
$var = "1.2";
type: string
10 out of a possible 11 are correct for a score of 90%
----
$var = "true";
type: string
100% perfect!
----
$var = false;
type: boolean
100% perfect!
----
$var = array(0 => "foo");
type: array
10 out of a possible 11 are correct for a score of 90%
----
$var = new test_parent();
type: object
100% perfect!
----
$var = NULL;
type: NULL
10 out of a possible 11 are correct for a score of 90%
----
$var = mysql_connect("localhost", "mysql_user", "mysql_pass");
type: resource
10 out of a possible 11 are correct for a score of 90%
----
3 quizzes out of 13 are perfect

128 out of 143 answers correct. -- Overall score: 89%


blackbeltboy47, almost forgot about you... just a moment, I?ll have yours.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Next

Return to phpBB3 Challenges at phpBB Academy

Who is online

Users browsing this forum: No registered users and 1 guest