php - Remove duplicate items from an array -
i use line of code below loop through table in database:
$items_thread = $connection -> fetch_all($sql);
and if print array out:
print_r($items_thread);
i this:
array ( [0] => array ( [recipientid] => 3 [recipientscreenname] => tom l [recipientfirstname] => thomas [recipientemail] => info@xx.com ) [1] => array ( [recipientid] => 3 [recipientscreenname] => tom l [recipientfirstname] => thomas [recipientemail] => info@xx.com ) [2] => array ( [recipientid] => 1 [recipientscreenname] => lau t [recipientfirstname] => tk [recipientemail] => lau@xx.co.uk ) )
but want rid of duplicate items in array, use array_unique
print_r(array_unique($items_thread));
i weird result below not quite looking for:
array ( [0] => array ( [recipientid] => 3 [recipientscreenname] => tom l [recipientfirstname] => thomas [recipientemail] => info@xx.com ) )
ideally, think should return this:
array ( [0] => array ( [recipientid] => 3 [recipientscreenname] => tom l [recipientfirstname] => thomas [recipientemail] => info@xx.com ) [1] => array ( [recipientid] => 1 [recipientscreenname] => lau t [recipientfirstname] => tk [recipientemail] => lau@xx.co.uk ) )
what shall right? have used wrong php syntax/default function?
the array_unique
function you. needed add sort_regular
flag:
$items_thread = array_unique($items_thread, sort_regular);
however, bren suggests, should in sql if possible.
Comments
Post a Comment