Page 1 of 1

array

Posted: Mon Jan 08, 2007 7:36 pm
by horszelim
hi.
Can anyone giv me ideas in solving question as below?

Parameter: An array of strings
Return value: A list of unique strings in the parameter array

Thanks

Posted: Mon Jan 08, 2007 7:41 pm
by volka

Posted: Mon Jan 08, 2007 7:45 pm
by jayshields
First idea to come into my head:
  • Sort the array elements alphabetically.
    Loop through every element (except the last one) and check to see if it's identical to the element after it.
    If it is not identical, add it to a seperate array.
Ok, that's flawed, because it will just return an array containing every string in the original array, but with no duplicates. That's not what you're after is it?

array of numbers (pass-by-value) arrays (pass-byreference)

Posted: Mon Jan 08, 2007 7:49 pm
by horszelim
Thanks a lot. :D

This is another question.
I din expect complete coding.
I just need some ideas.


Parameter: An array of numbers (pass-by-value) and two arrays (pass-byreference)
Return value: None
Result: The first pass-by-reference parameter must have the values of the given array

Re: array of numbers (pass-by-value) arrays (pass-byreferenc

Posted: Mon Jan 08, 2007 7:53 pm
by jayshields
horszelim wrote: Parameter: An array of numbers (pass-by-value) and two arrays (pass-byreference)
Return value: None
Result: The first pass-by-reference parameter must have the values of the given array
That doesn't make sense. I presume you're wanting it to return a boolean depending on the success. I don't understand what you've specified in the parameter or result bit either; are you wanting to specify 2 array's of numbers and see if they contain the same values?

Posted: Mon Jan 08, 2007 8:14 pm
by horszelim
yes, it need to return a boolean depending on the success.

There are two array.
First is an array of numbers which is pass-by-value.
Second is two arrays which pass-byreference.

After that, the first pass-by-reference parameter must have the values of the given array(first array)

Thanks

Posted: Mon Jan 08, 2007 8:52 pm
by volka
I still do not understand
horszelim wrote:There are two array.
ok, 2. But
horszelim wrote:First is an array of numbers which is pass-by-value.
Second is two arrays which pass-byreference.
now there are three of them?
After that, the first pass-by-reference parameter must have the values of the given array(first array)
all three are "given", which one do you mean? What does "have the values" mean? Please elucidate.
Maybe you're looking for something like http://de3.php.net/array_intersect or http://de3.php.net/array_diff , maybe not.

Posted: Mon Jan 08, 2007 8:59 pm
by horszelim
sorry cos make u confuse.

only have 2 array
first array are key in by user.
let say user key in 3,89,12,6
then all the number will keep in first array.
after that, there are 2 value in second array which same with the first and second value of the first array.
So, the second array will have 3,89

thanks

Posted: Mon Jan 08, 2007 9:03 pm
by volka
horszelim wrote:sorry cos make u confuse.
I'm sorry, too. Because now I'm even more confused and have no clue what you're trying to do. Good luck anyway.

thanks

Posted: Mon Jan 08, 2007 9:06 pm
by horszelim
really sorry.
Anyway, thanks for ur help. :)

Posted: Tue Jan 09, 2007 12:56 am
by matthijs
Maybe if you post some example code it's easier for others to see what you mean. Doesn't mater if it's not working yet. Some people here read better PHP then plain english ;)
(don't forget to use the proper code tags)