Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php get unique values by key from array

$array = array(
	array('group' => 'test', 'name' => 'Jane'),
    array('group' => 'test', 'name' => 'John'),
    array('group' => 'admin', 'name' => 'superadmin')
);
$unique_values_by_key = array_unique(array_column($array, 'group'));
Comment

array unique php

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>
Comment

array unique php

<?php
    // Syntax: array_unique(array $array, int $flags = SORT_STRING): array
    // Desc: Removes duplicate values from an array
    $arr = Array("red", "red", "green", "blue", "blue", "white");
    echo "<pre>";
    print_r($arr);
    echo "</pre> <br><br>";
    
    $arrUnique = array_unique($arr);

    echo "<pre>";
    print_r($arrUnique);
    echo "</pre> <br><br>";

    /* -------- output -----------
    Array
    (
        [0] => red
        [1] => red
        [2] => green
        [3] => blue
        [4] => blue
        [5] => white
    )
    
    Array
    (
        [0] => red
        [2] => green
        [3] => blue
        [5] => white
    )
    */
?>
Comment

unique key value array php

$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
Comment

PREVIOUS NEXT
Code Example
Php :: php function exists 
Php :: php install xdebug mac 
Php :: mac os change the php verison 
Php :: php capitalize each word 
Php :: laravel firstorcreate 
Php :: php array join 
Php :: php usort keep keys 
Php :: array to string conversion in php 
Php :: Artisan::call for all catch clear in laravel 
Php :: laravel blade file naming conventine 
Php :: CodeIgniter get_where order_by 
Php :: php mysql if exists 
Php :: php intl 
Php :: send email php smtp hostinger 
Php :: wpdb-prepare 
Php :: sanitize user input php 
Php :: artisan mograte particular tabel 
Php :: Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in 
Php :: undefined method JeroenNotenLaravelAdminLteHelpersMenuItemHelper::isSearchBar() 
Php :: Array Contant PHP 
Php :: laravel string capitalize in view 
Php :: php replace every occurrence of character in string 
Php :: update pdo mysql php 
Php :: laravel token logout 
Php :: php clone object 
Php :: previous month number in php 
Php :: how to format php document in vs code 
Php :: dont show file type in url 
Php :: Laravel Boot strap Pagination 
Php :: json whereIn laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =