Skip to content

Instantly share code, notes, and snippets.

@AceAce2025
Created December 1, 2022 05:11
Show Gist options
  • Select an option

  • Save AceAce2025/1299d1a7132a106f8bd6c76e59a1dad6 to your computer and use it in GitHub Desktop.

Select an option

Save AceAce2025/1299d1a7132a106f8bd6c76e59a1dad6 to your computer and use it in GitHub Desktop.

Revisions

  1. AceAce2025 created this gist Dec 1, 2022.
    26 changes: 26 additions & 0 deletions array_unique_multidimesional.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php

    // https://www.php.net/manual/en/function.array-unique.php#116302

    $details = array(
    0 => array("id"=>"1", "name"=>"Mike", "num"=>"9876543210"),
    1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"),
    2 => array("id"=>"1", "name"=>"Mathew", "num"=>"784581254"),
    );

    $details = array_unique_multidimesional($details,'id');

    function array_unique_multidimesional($array, $key) {
    $temp_array = array();
    $i = 0;
    $key_array = array();

    foreach($array as $val) {
    if (!in_array($val[$key], $key_array)) {
    $key_array[$i] = $val[$key];
    $temp_array[$i] = $val;
    }
    $i++;
    }
    return $temp_array;
    }