fork(1) download
  1. <?php
  2.  
  3. $products=Array
  4. (
  5. 0 => Array
  6. (
  7. 0 => 'Intel I3',
  8. 1 => 146,
  9. 2 => 'intel-i3'
  10. ),
  11.  
  12. 1 => Array
  13. (
  14. 0 => 'Intel I3',
  15. 1 => 146,
  16. 2 => 'intel-i3'
  17. ),
  18. 2 => Array
  19. (
  20. 0 => 'Intel I3',
  21. 1 => 250,
  22. 2 => 'intel-i3'
  23. ),
  24. 3 => Array
  25. (
  26. 0 => 'AMD graphic',
  27. 1 => 146,
  28. 2 => 'amd-graphic'
  29. )
  30. );
  31.  
  32. define("PRODUCT_TITLE", 0);
  33.  
  34. $titleCounts = array();
  35.  
  36. foreach ($products as &$product) {
  37. $productTitle = $product[PRODUCT_TITLE];
  38.  
  39. if (!isset($titleCounts[$productTitle])) {
  40. $titleCounts[$productTitle] = 0;
  41. } else {
  42. $titleCounts[$productTitle]++;
  43. $product[PRODUCT_TITLE] = ($productTitle.'_'.$titleCounts[$productTitle]);
  44. }
  45. }
  46.  
  47. print_r($products);
  48.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => Intel I3
            [1] => 146
            [2] => intel-i3
        )

    [1] => Array
        (
            [0] => Intel I3_1
            [1] => 146
            [2] => intel-i3
        )

    [2] => Array
        (
            [0] => Intel I3_2
            [1] => 250
            [2] => intel-i3
        )

    [3] => Array
        (
            [0] => AMD graphic
            [1] => 146
            [2] => amd-graphic
        )

)