Skip to content

Instantly share code, notes, and snippets.

@LukeXF
Created June 27, 2015 22:31
Show Gist options
  • Save LukeXF/a785b395be0a784f43a4 to your computer and use it in GitHub Desktop.
Save LukeXF/a785b395be0a784f43a4 to your computer and use it in GitHub Desktop.
A PHP skill test
<?php
// please fill-in the body of the functions
// using methods to produce the suggested output
/* function tests */
//echo remove_nonAtoZ("BA'3Ndf$%^A&*(nN)A")."</br>"."</br>";
//echo first_char_caps('TEST DATA bleh Orange')."</br>"."</br>";
//echo date_8_hours_ago()."</br>"."</br>";
//echo table_columns(array('apple', 'orange', 'monkey', 'potato', 'cheese', 'badger', 'turnip'), 2)."</br>"."</br>";
//
//$filename = 'coverage.csv';
//$output = load_csv($filename);
//var_dump($output)."</br>";
function remove_nonAtoZ($input) {
/*
// example data
$input = "BA'3Ndf$%^A&*(nN)A";
$output = "BANANA";
*/
}
function first_char_caps($input) {
/*
// example data
$input = 'TEST DATA bleh Orange';
$output = 'Test Data Bleh Orange';
*/
}
function load_csv($filename) {
// load data from a file with three
// comma-separated text fields into a MySQL table
// called csv_data
}
function date_8_hours_ago() {
// return a string of the date and time
// eight hours back from now
// e.g.
//return "Wed 1st Jan 5:23am";
}
function email_postvars() {
// example data
/*$_POST = array('forename' => 'Dave',
'surname' => 'Johnson',
'email' => 'dave.johnson@example.com',
'extra_age' => '24',
'extra_hobbies' => 'Cricket, cycling and chess',
'extra_height' => '2 metres')
*/
// output - an email
// Email header
// Email body (Additional info = any fields with 'extra_' prefix)
}
function table_columns($input, $cols) {
/*
// example data
$input = array('apple', 'orange', 'monkey', 'potato', 'cheese', 'badger', 'turnip');
$cols = 2;
$output = <<<OUT
<table>
<tr>
<td>apple</td>
<td>cheese</td>
</tr>
<tr>
<td>orange</td>
<td>badger</td>
</tr>
<tr>
<td>monkey</td>
<td>turnip</td>
</tr>
<tr>
<td>potato</td>
<td></td>
</tr>
</table>
OUT;
*/
}
function add_accesskeys($input) {
/*
// example data
$input = array(
array('filename' => 'home.html',
'title' => 'home page'),
array('filename' => 'products.html',
'title' => 'products'),
array('filename' => 'contact.html',
'title' => 'contact'),
array('filename' => 'prices.html',
'title' => 'prices'));
$output = <<<OUT
<ul>
<li><a href="home.html" accesskey="h"><em>h</em>ome page</a></li>
<li><a href="products.html" accesskey="p"><em>p</em>roducts</a></li>
<li><a href="contact.html" accesskey="c"><em>c</em>ontact</a></li>
<li><a href="prices.html" accesskey="r">p<em>r</em>ices</a></li>
</ul>
OUT;
*/
}
function returnKey($array) {
/*example data
$array[0] = 3, $array[1] = -2, $array[2] = 5, $array[3] = 3, $array[4] = 1, $array[5] = -2, $array[6] = 7
//function
return 3;
return index (int) 3 because sum of all values before $array[3] (6) equal sum of all values above $array[3] (6)
write function that will return first index of any array that meets the above condition, if no match -1;
assume indices are all integers ordered by size ASC already and values are all numbers;
*/
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment