Code Academy PHP problem sets

<html>
<p>
<?php
// Create an array and push on the names
// of your closest family and friends
$fam=array();
array_push($fam,"Jeana");
array_push($fam,"Niko");
array_push($fam,"Kaz");
array_push($fam,"Hiroko");
array_push($fam,"Yoko");
print count($fam);
$n_elements=count($fam);
// Sort the list
sort($fam);
// Randomly select a winner!
$roll=rand(1,$n_elements);
print $roll;
$which_person= $array[$roll];
print $which_person;
// Print the winner's name in ALL CAPS
$which_person2=strtoupper($which_person);
print $which_person2;

?>
</p>
</html>

 

 

<html>
<p>
<?php
// Create an array with several elements in it,
// then sort it and print the joined elements to the screen
$array=array(4,3,2,5);
sort($array);
print join(",", $array);
?>
</p>
<p>
<?php
// Reverse sort your array and print the joined elements to the screen

rsort($array);
print join(",",$array);

?>
</p>
</html>

 

 

http://www.w3schools.com/php/php_echo_print.asp

<!DOCTYPE html>
<html>
<head>
<title>Your own do-while</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<?php
//write your do-while loop below
do {
$roll=rand(1,6);
echo "$roll";
} while ($roll !=6);

?>
</body>
</html>

 

FUNCTIONS

$length=strlen("kazuaki");
print $length;

 

<html>
<p>
<?php
// Get a partial string from within your own name
// and print it to the screen!

?>
</p>
<p>
<?php
// Make your name upper case and print it to the screen:
$myname="Kaz";
$uppercase=strtoupper($myname);
print $uppercase;
?>
</p>
<p>

<?php
// Make your name lower case and print it to the screen:
$lowercase = strtolower($uppercase);
print $lowercase;
?>
</p>
</html>

 

 

 

<html>
<p>
<?php
// Get a partial string from within your own name
// and print it to the screen!
$myname="Kazuaki";
$partial = substr($myname, 0, 3);
print $partial;
?>
</p>

<p>
<?php
// Make your name upper case and print it to the screen:
$uppercase=strtoupper($partial);
print $uppercase;
?>
</p>

<p>

<?php
// Make your name lower case and print it to the screen:
$lowercase = strtolower($uppercase);
print $lowercase;
?>
</p>
</html>

 

 

<html>
<p>
<?php
// Print out the position of a letter that is in
// your own name
$x=strpos("kazuaki","u");
print $x;
?>
</p>
<p>
<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message
if (strpos("kazuaki","x")===false){
print "Sorry, no x in the name kazuaki";
}
?>
</p>
</html>

 

 

<html>
<p>
<?php
// Use rand() to print a random number to the screen
print rand();
?>
</p>
<p>
<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$length=strlen("kazuaki");
//print $length;
$random_n=rand(1,$length);
//print $random_n;
$random_letter=substr("kazuaki",$random_n-1,1);
print $random_letter;

?>
</p>
</html>

 

 

<html>
<p>
<?php
// Create an array and push 5 elements on to it, then
// print the number of elements in your array to the screen
$fav_food=array();
array_push($fav_food,"Sushi");
array_push($fav_food,"Curry");
array_push($fav_food,"Rice");
array_push($fav_food,"Gyoza");
array_push($fav_food,"Ramen");
print count($fav_food);
?>
</p>
</html>

1 comment to Code Academy PHP problem sets

  • I agreed with what your point out. And to me, that re issues that anyone want to be programmer must be able to figure out themself. Problem solving skills is needed in any levels of programmers live. Not the ultimate usability is needed for them, when learning somethings, we tended to hack and find ways to make it work anyway. And anyone found Codecademy is too complicated for them should be realized they are more consumer than creator type. It the least complicated experience and straightforward to learn coding to me.

Leave a Reply