please help how do i create my own functions

loudog

New member
Jun 19, 2011
2
0
0
hey guys, I just got an assignment which im having alot of trouble with and i was hoping that you guy's could help me.
The assignment is that i must write my own functions. I've read the php manual and yes i do understand how to write a function but im not very good at writing my own.Its not so much the the function but what type of argument should i use that gets me confuse in this assignment. i don't know if i use and if statement,while loop,or , foreach. I look at the examples the they have in php manaul and it just makes me feel even more lost this is my first time and what makes it worst is that i can't copy someone else function i have to write my own.

In this assignment you will have to
rewrite some of the built-in functions. For example: If I ask you
rewrite the function strrev() (strrev reverses a given string),you can
do something like this:

function dan_strrev($input) {

$i = 0;
$myLen = 0;

while (true) {
if (isset($input[$i])) {
$myLen = $myLen + 1;
$i = $i + 1;
}
else {
break;
}
}

$temp = '';
for ($i = $myLen - 1; $i >= 0; $i--) {
$temp = $temp.$input[$i];
}
return $temp;
}

echo dan_strrev('Hello');
echo strrev('Hello');

So, you can see that both the built-in function strrev() as well as
the one we wrote (dan_strrev()) gives the same output.

Please do the same for the following built-in functions:
1).str_pad — Pad a string to a certain length with another string

2).str_split — Convert a string to an array

3).str_repeat — Repeat a string

4).array_combine — Creates an array by using one array for keys and
another for its values

5).array_flip — Exchanges all keys with their associated values in an array

6).array_pop — Pop the element off the end of array

7).array_udiff_assoc — Computes the difference of arrays with
additional index check, compares data by a callback function

.array_walk — Apply a user function to every member of an array

9).array_uintersect — Computes the intersection of arrays, compares
data by a callback function

10).usort — Sort an array by values using a user-defined comparison function

11).array_flip — Exchanges all keys with their associated values in an array

12).ksort — Sort an array by key

13).in_array — Checks if a value exists in an array

14).array_search — Searches the array for a given value and returns
the corresponding key if successful

15).array_merge — Merge one or more arrays

If you want to know how these functions,please take a look at the php
manual/documentation on php.net.

Email me if you have not understood anything that I have explained so
far. I am not setting a deadline but it will be good if you can
complete this in the next 2 weeks