: This article mainly introduces de-duplicated elements in PHP arrays. For more information about PHP tutorials, see. Remove repeated elements from the array:
1. pure natural raw methods from data structures:
Foreach ($ feerecord as $ value)
{
$ Fee_record_id = $ value ['feerecordid'];
If (! In_array ($ fee_record_id, $ fee_record_id_arr ))
{
$ Fee_record_id_arr [] = $ fee_record_id;
}
Else
{
Continue;
}
}
Return $ fee_record_id_arr;
2. PHP functions should be reasonably used, and the code implementation should be: one line
$ Fee_recorda_id_arr = array_values (array_unique (array_column ($ feerecord, 'feerecordid ')));
Three functions hints:
Array_values ($ arr) returns all values in the array and creates a digital index.
The array_unique ($ arr) array is de-duplicated, but the returned key values are not sequential.
Array_column ($ arr, $ key) retrieves all element values of key = $ key in a multi-dimensional array and forms an array of numbers.
The above introduces PHP array de-duplication elements, including the content, hope to be helpful to friends who are interested in PHP tutorials.