fork(1) download
  1. <?php
  2. class Product
  3. {
  4. public function __construct($ean, $price, $count){
  5. $this->ean = $ean;
  6. $this->productPrice = $price;
  7. $this->productCount = $count;
  8. }
  9.  
  10. public function __get($property) {
  11. if (property_exists($this, $property)) {
  12. return $this->$property;
  13. }
  14. }
  15.  
  16. }
  17.  
  18.  
  19. function removeduplicateKeys($data){
  20.  
  21. $tempArr = array_unique(array_column($data, 'ean'));
  22. return array_intersect_key($data, $tempArr);
  23.  
  24. }
  25.  
  26.  
  27. // $arr =array(
  28. // "0" => Array
  29. // (
  30. // "ean" => 6900532615069,
  31. // "productPrice" => 1140,
  32. // "productCount" => 5
  33. // ),
  34. // "1" => Array
  35. // (
  36. // "ean" => 6900532615069,
  37. // "productPrice" => 1140,
  38. // "productCount" => 50
  39. // ),
  40. // "2" => Array
  41. // (
  42. // "ean" => 6900535364122,
  43. // "productPrice" => 1140,
  44. // "productCount" => 50
  45. // ),
  46.  
  47. // "3" => Array
  48. // (
  49. // "ean" => 6900532615069,
  50. // "productPrice" => 1140,
  51. // "productCount" => 10,
  52. // ));
  53. $arr =array(
  54. "0" => Array
  55. (
  56. "ean" => 6900532615069,
  57. "productPrice" => 1140,
  58. "productCount" => 10,
  59. ),
  60. "1" => Array
  61. (
  62. "ean" => 6900532615069,
  63. "productPrice" => 1140,
  64. "productCount" => 50
  65. ),
  66. "2" => Array
  67. (
  68. "ean" => 6900535364122,
  69. "productPrice" => 1140,
  70. "productCount" => 50
  71. ),
  72. "3" => Array
  73. (
  74. "ean" => 6900535364122,
  75. "productPrice" => 1140,
  76. "productCount" => 500
  77. ),
  78. "4" => Array
  79. (
  80. "ean" => 6900535364122,
  81. "productPrice" => 1140,
  82. "productCount" => 0
  83. ),
  84. "5" => Array
  85. (
  86. "ean" => 6900532615069,
  87. "productPrice" => 1140,
  88. "productCount" => 5,
  89. ));
  90.  
  91. print_r(removeduplicateKeys($arr));
Success #stdin #stdout 0.01s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [ean] => 6900532615069
            [productPrice] => 1140
            [productCount] => 10
        )

    [2] => Array
        (
            [ean] => 6900535364122
            [productPrice] => 1140
            [productCount] => 50
        )

)