Hi i am running the following code.
foreach ($response as $object) {
$basename = basename($object);
$structure = explode("/", $object);
echo $structure[0] . '<br>';
}
this returns the following.
MINOFSOUDUB412
MINOFSOUDUB412
MINOFSOUDUB412
MotionTracker.zip
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
MotionTracker
i only want it to return one unique name like below
MINOFSOUDUB412
MotionTracker.zip
MotionTracker
Can someone help me with this
Thanks
You will get the best performance out of using the value as an array key:
This seems a bit crazy at first. After all, why use the string as an array key?
Well:
$unique[$name]is O(1) (meaning no matter how large the array is it takes the same amount of time) whereas in_array($name, $unique) is O(n) meaning it grows with how many entries are in the array.Just for reference the full version of it in your code would be:
The O(n) (slower version) would be:
The slower version is slower, but people not intimately familiar with PHP arrays may find it a bit easier to read.