UmarAbbasKhan UmarAbbasKhan - 10 months ago 69
PHP Question

PHP Array Unique

I believe my issue is fairly basic and simple, but I think I am not getting through it.I have a PHP array which has been dynamically populated with data from the database

$SelectPInvoicesList ="SELECT * FROM AllDataEntriesList
WHERE BusinessID = '{$businessid}'
AND DocumentType = 'purchaseinvoice'
$SelectPInvoicesList_query = mysqli_query($connection, $SelectPInvoicesList);
die ("Database query for searching Purchase Invoices failed.".mysqli_error($connection));
while ($SelectPInvoicesList_array = mysqli_fetch_assoc($SelectPInvoicesList_query)){


And this gives me an array

Array ( [0] => pk-000000003-purchaseinvoice-1
[1] => pk-000000003-purchaseinvoice-1

When I apply
array_unique($PInvoicesList, SORT_STRING);
, I get both of both elements in the array, whereas they both have the same data. I used this function as
array_unique($PInvoicesList, SORT_REGULAR);
but still both the elements in the array are appearing and they have the exact same data. Can anyone guide me how can I remove the elements with duplicate values from this array?

Answer Source

The array_unique() removes duplicate values from an array. Just use array_unique() without sorting

Refer this

$result = array_unique($PInvoicesList);