fork(3) 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. print_r($tempArr);
  23. return array_intersect_key($data, $tempArr);
  24.  
  25. }
  26.  
  27.  
  28. // $arr =array(
  29. // "0" => Array
  30. // (
  31. // "ean" => 6900532615069,
  32. // "productPrice" => 1140,
  33. // "productCount" => 5
  34. // ),
  35. // "1" => Array
  36. // (
  37. // "ean" => 6900532615069,
  38. // "productPrice" => 1140,
  39. // "productCount" => 50
  40. // ),
  41. // "2" => Array
  42. // (
  43. // "ean" => 6900535364122,
  44. // "productPrice" => 1140,
  45. // "productCount" => 50
  46. // ),
  47.  
  48. // "3" => Array
  49. // (
  50. // "ean" => 6900532615069,
  51. // "productPrice" => 1140,
  52. // "productCount" => 10,
  53. // ));
  54. $arr =array(
  55. "0" => Array
  56. (
  57. "ean" => 6900532615069,
  58. "productPrice" => 1140,
  59. "productCount" => 10,
  60. ),
  61. "1" => Array
  62. (
  63. "ean" => 6900532615069,
  64. "productPrice" => 1140,
  65. "productCount" => 50
  66. ),
  67. "2" => Array
  68. (
  69. "ean" => 6900535364122,
  70. "productPrice" => 1140,
  71. "productCount" => 50
  72. ),
  73. "3" => Array
  74. (
  75. "ean" => 6900535364122,
  76. "productPrice" => 1140,
  77. "productCount" => 500
  78. ),
  79. "4" => Array
  80. (
  81. "ean" => 6900535364122,
  82. "productPrice" => 1140,
  83. "productCount" => 0
  84. ),
  85. "5" => Array
  86. (
  87. "ean" => 6900532615069,
  88. "productPrice" => 1140,
  89. "productCount" => 10,
  90. ));
  91.  
  92. print_r(removeduplicateKeys($arr));
Success #stdin #stdout 0.05s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 6900532615069
    [2] => 6900535364122
)
Array
(
    [0] => Array
        (
            [ean] => 6900532615069
            [productPrice] => 1140
            [productCount] => 10
        )

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

)