array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
horszelim
Forum Newbie
Posts: 7
Joined: Mon Jan 08, 2007 7:28 pm

array

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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?
horszelim
Forum Newbie
Posts: 7
Joined: Mon Jan 08, 2007 7:28 pm

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

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

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

Post 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?
horszelim
Forum Newbie
Posts: 7
Joined: Mon Jan 08, 2007 7:28 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
horszelim
Forum Newbie
Posts: 7
Joined: Mon Jan 08, 2007 7:28 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
horszelim
Forum Newbie
Posts: 7
Joined: Mon Jan 08, 2007 7:28 pm

thanks

Post by horszelim »

really sorry.
Anyway, thanks for ur help. :)
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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)
Post Reply