[FX.php List] A little more clarity on my array_unique question

Bob Patin bob at patin.com
Thu Apr 12 09:23:07 MDT 2007


Perhaps I should explain more what I'm trying to achieve:

I'm returning an array $vlData that has auto names & image names,  
like this:

Chevrolet Astro ---- $vlData['target_name'][0]
Chevrolet Astro.jpg ---- $vlData['target_image'][0]

When I return this array, there can be a lot of records with the same  
vehicle in them, and I need to display a single button for each vehicle.

So I've been using a FOREACH loop to cycle thru the results, and then  
create a 2nd array that contains only non-duplicates.

The problem is that some models, Chevrolet particularly, have a ton  
of matches (in this case, 1722), and the loop takes a long time to  
finish.

So here's my code so far; this works, but it's slow as Christmas:

<?php
$c=0;
//nuke the array first
while($c<25){
	$n[$c]='';
	$i[$c]='';
	$c++;
}
$thename='';
$c=0;
$n = array('thename');
$i = array('image');

foreach($vlResult['data']as $key=>$vlData) {
	if ($thename <> $vlData['target_name'][0]){
		$n[$c] = $vlData['target_name'][0];
		$i[$c] = "/images".$reportyear."/".$vlData['target_image'][0];
		$thename = $vlData['target_name'][0];
		$c++;
	}
}
?>

Any thoughts? :)

Thanks,

Bob






More information about the FX.php_List mailing list