sanchescom / php-wifi

Cross-platform PHP library for scan, connect and disconnect Wi-Fi networks.
GNU General Public License v3.0
49 stars 14 forks source link

Sort $networks by ssid, only display each ssid once … #10

Closed fooness closed 4 years ago

fooness commented 4 years ago

Is it possible to sort the $networks array(?) alphabetically by ssid and also to display each ssid only once?

Tried it with array_unique(), but couldn’t figure out how to modify $networks in any way.

Here’s what I’m using on my Kirby CMS page:

<?php use Sanchescom\WiFi\WiFi; $networks = WiFi::scan()->getAll() ?>
<?php foreach ($networks as $network): ?>
            <option value="<?= strtolower($network); ?>"><?= $network->ssid ?></option>
<?php endforeach ?>
sanchescom commented 4 years ago

Yes, it is quietly easy. Method 'scan()' return a collection. Just do the next thing:

$networks = \Sanchescom\WiFi\WiFi::scan()->unique('ssid')->sortBy('ssid')->getAll();

fooness commented 4 years ago

Thank you so much, that works perfectly.

Is there any documentation available for questions like mine above? Feels like there’s very lots of great features in php-wifi.

sanchescom commented 4 years ago

Oh, I didn't even think of that. I will definitely expand the documentation. Thanks a lot.