Re: [PHP] array_unique by id multi-dimensional array

2011-10-28 Thread Tontonq Tontonq
let me explain again
this is my array
Array
(
[0] = Array
(
[likes] = 137846
[name] = blabla
[access_token] = AAABZBD
[id] = 157644197612598
[link] = http://www.facebook.com/blabla
)

[1] = Array
(
[likes] = 137698
[name] = blabla
[access_token] = AAAnnL
[id] = 157644197612598
[link] = http://www.facebook.com/blabla
)

[2] = Array
(
[likes] = 134391
[name] = sieaq
[access_token] = AAA04
[id] = 163744743683729
[link] = http://www.facebook.com/zart
)


[3] = Array
(
[name] = defolaq
[access_token] = AAAZD
[id] = 139820007610
[link] = http://www.facebook.com/apps/application.php?id=239820007640
[likes] = 0
)

[4] = Array
(
[name] = falan
[access_token] = AAW4NNGAZDZD
[id] = 374971333999
[link] = http://www.facebook.com/apps/application.php?id=37495199
[likes] = 0
)

[5] = Array
(
[name] = filan
[access_token] = AAABZCTCw
[id] = 237184173662497
[link] = http://www.facebook.com/pages/filan/237184173662497
[likes] = 0
)

[6] = Array
(
[name] = bigit
[access_token] = Jj77twGFvS8YyB
[id] = 10497735291210
[link] = http://www.facebook.com/pages/bigit/10497735291210
[likes] = 0
)
)

but as you see there are 2 sub array with [id] =  157644197612598
i want to delete sub arrays repeated with same id.?

2011/10/28 tamouse mailing lists tamouse.li...@gmail.com

 On Thu, Oct 27, 2011 at 10:31 AM, Tontonq Tontonq root...@gmail.com
 wrote:
  i have an array like
 
   [0] = Array
  (
  [likes] = 113091
   [name] = blabla
   [access_token] = AAABZCTx
  [id] = 188206217874932
 
  )
 
   [1] = Array
  (
  [likes] = 113091
  [name] = blabla
  [access_token] =   AAABZCTz
  [id] = 188206217874932
)
 
  i want to filter the array by [id] sub value?
 

 Not quite sure what you mean by filter in this case, but the
 function that pops to mind is
 http://www.php.net/manual/en/function.array-filter.php, which applies
 a callback function to each member of the array where you can
 determine if it should be included in the filtered list by returning
 true.



Re: [PHP] array_unique by id multi-dimensional array

2011-10-28 Thread sivaji j.g
On Fri, Oct 28, 2011 at 1:22 PM, Tontonq Tontonq root...@gmail.com wrote:

 let me explain again
 this is my array
 Array
 (
 [0] = Array
 (
 [likes] = 137846
 [name] = blabla
 [access_token] = AAABZBD
 [id] = 157644197612598
 [link] = http://www.facebook.com/blabla
 )

 [1] = Array
 (
 [likes] = 137698
 [name] = blabla
 [access_token] = AAAnnL
 [id] = 157644197612598
 [link] = http://www.facebook.com/blabla
 )

 [2] = Array
 (
 [likes] = 134391
 [name] = sieaq
 [access_token] = AAA04
 [id] = 163744743683729
 [link] = http://www.facebook.com/zart
 )


 [3] = Array
 (
 [name] = defolaq
 [access_token] = AAAZD
 [id] = 139820007610
 [link] = http://www.facebook.com/apps/application.php?id=239820007640
 [likes] = 0
 )

 [4] = Array
 (
 [name] = falan
 [access_token] = AAW4NNGAZDZD
 [id] = 374971333999
 [link] = http://www.facebook.com/apps/application.php?id=37495199
 [likes] = 0
 )

 [5] = Array
 (
 [name] = filan
 [access_token] = AAABZCTCw
 [id] = 237184173662497
 [link] = http://www.facebook.com/pages/filan/237184173662497
 [likes] = 0
 )

 [6] = Array
 (
 [name] = bigit
 [access_token] = Jj77twGFvS8YyB
 [id] = 10497735291210
 [link] = http://www.facebook.com/pages/bigit/10497735291210
 [likes] = 0
 )
 )

 but as you see there are 2 sub array with [id] =  157644197612598
 i want to delete sub arrays repeated with same id.?


If my understanding is right, a simple foreach loop and unset() will do
this. Below is the untested version of snippet I would use to remove the
duplicate sub arrays,

$id = array();
foreach ($items as $key = $item) {
  if (in_array($item['id'], $id)) {
unset($items[$key]);
  }
  else {
$id[] = $item['id'];
  }
}


-- 
Sivaji
http://sivaji.drupalgardens.com
@sivaji_ganesh https://twitter.com/#%21/sivaji_ganesh in twitter
sivaji2...@gmail.com
Gtalk / Skype: sivaji2009






Re: [PHP] array_unique by id multi-dimensional array

2011-10-28 Thread Tontonq Tontonq
thanks it works

2011/10/28 sivaji j.g sivaji2...@gmail.com


 On Fri, Oct 28, 2011 at 1:22 PM, Tontonq Tontonq root...@gmail.comwrote:

 let me explain again
 this is my array
 Array
 (
 [0] = Array
 (
 [likes] = 137846
 [name] = blabla
 [access_token] = AAABZBD
 [id] = 157644197612598
 [link] = http://www.facebook.com/blabla
 )

 [1] = Array
 (
 [likes] = 137698
 [name] = blabla
 [access_token] = AAAnnL
 [id] = 157644197612598
 [link] = http://www.facebook.com/blabla
 )

 [2] = Array
 (
 [likes] = 134391
 [name] = sieaq
 [access_token] = AAA04
 [id] = 163744743683729
 [link] = http://www.facebook.com/zart
 )


 [3] = Array
 (
 [name] = defolaq
 [access_token] = AAAZD
 [id] = 139820007610
 [link] = http://www.facebook.com/apps/application.php?id=239820007640
 [likes] = 0
 )

 [4] = Array
 (
 [name] = falan
 [access_token] = AAW4NNGAZDZD
 [id] = 374971333999
 [link] = http://www.facebook.com/apps/application.php?id=37495199
 [likes] = 0
 )

 [5] = Array
 (
 [name] = filan
 [access_token] = AAABZCTCw
 [id] = 237184173662497
 [link] = http://www.facebook.com/pages/filan/237184173662497
 [likes] = 0
 )

 [6] = Array
 (
 [name] = bigit
 [access_token] = Jj77twGFvS8YyB
 [id] = 10497735291210
 [link] = http://www.facebook.com/pages/bigit/10497735291210
 [likes] = 0
 )
 )

 but as you see there are 2 sub array with [id] =  157644197612598
 i want to delete sub arrays repeated with same id.?


 If my understanding is right, a simple foreach loop and unset() will do
 this. Below is the untested version of snippet I would use to remove the
 duplicate sub arrays,

 $id = array();
 foreach ($items as $key = $item) {
   if (in_array($item['id'], $id)) {
 unset($items[$key]);
   }
   else {
 $id[] = $item['id'];
   }
 }


 --
 Sivaji
 http://sivaji.drupalgardens.com
 @sivaji_ganesh https://twitter.com/#%21/sivaji_ganesh in twitter
 sivaji2...@gmail.com
 Gtalk / Skype: sivaji2009






Re: [PHP] array_unique by id multi-dimensional array

2011-10-27 Thread tamouse mailing lists
On Thu, Oct 27, 2011 at 10:31 AM, Tontonq Tontonq root...@gmail.com wrote:
 i have an array like

  [0] = Array
 (
 [likes] = 113091
  [name] = blabla
  [access_token] = AAABZCTx
 [id] = 188206217874932

 )

  [1] = Array
 (
 [likes] = 113091
 [name] = blabla
 [access_token] =   AAABZCTz
 [id] = 188206217874932
   )

 i want to filter the array by [id] sub value?


Not quite sure what you mean by filter in this case, but the
function that pops to mind is
http://www.php.net/manual/en/function.array-filter.php, which applies
a callback function to each member of the array where you can
determine if it should be included in the filtered list by returning
true.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php