Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Producing an array with unique values
May 6, 2010, 3:37 pm
rate this thread
I have an array
$test ('value1' => '', 'value2' => '', 'value3' => '');
and a loop, where an instance of $test is generated, and then added to
another array through the loop.
My question is, assuming that each $test is treated like a row, how do
I remove rows where value1 is a duplicate?
- The Natural Philosopher
May 6, 2010, 3:43 pm
Re: Producing an array with unique values
You can use associative array instead of numeric for $cumulative
array. Something like this:
$cumulative[$test['value1']] = $test;
This way you don't need to remove duplicates (since, if there is
array's key that corresponds to 'value1' of the $test array, it won't
be added and so there won't be duplicates). If you need numeric array,
you can always copy it (with "array_values" for example).
- » no exception details in modular Zend framework application
- — Next thread in » PHP Scripting Forum