Jump to content

[SOLVED] Two array questions


Agum

Recommended Posts

I have two questions regarding array. I would like to do the following in an efficient way.

 

1) I have two arrays. They contain ID numbers (unique). The first array has, say 100 elements. The second array has, say 20 elements. Every ID that appears in second array is also in the first array (guaranteed). What is the best way to search in the first array and remove every element that appears in the second array?

 

2) I have a multidimensional array/hash like this:

arr[0]['id'] = 123;

arr[0]['name'] = "John Doe";

arr[1]['id'] = 456;

arr[1]['name'] = "Peter Smith";

...

I would like to "sort" this array based on the "name" part of the array. The id number needs to be kept with that particular name it comes with. What's the best way to do this?

 

Thanks.

 

Link to comment
Share on other sites

Thanks Barand.

 

One more quick question.

What is the best way to concatenate an array into one string (comma separated values)?

Just loop through it and do $str .= ... ?

Or is there a function?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.