You can wrap everything in the DeviceInfo class, and then just use the properties of this class.
class DeviceInfo { public $c_devices; public $c_active; public $c_inactive; public $c_offline; public function __construct($cpe_mac) { $count_device = VSE::count_device($cpe_mac); $this->c_devices = $count_device['Count_of_devices']; $this->c_active = $count_device['Count_of_active']; $this->c_inactive = $count_device['Count_of_inactive']; $this->c_offline = $count_device['Count_of_offline']; } }
Have a class in your own file called DeviceInfo.php, and then where you need it, just
include_once("DeviceInfo.php");
at the top of the file and create a new instance of this class. (I use include_once to make sure the DeviceInfo class is not overridden if it is already defined)
$deviceInfo = new DeviceInfo($cpe_mac);
You can access values ββby accessing such properties.
$deviceInfo->c_devices;
This way you get code completion for the values ββ(depending on your IDE) and should not rely on remembering the key names of the array when you really want to use this information in your code.
If you want to take it one step further, you can even add getter functions to this class, so if you need to change how these values ββare computed or retrieved without changing the API in the future, it's a lot easier. It will look something like this:
class DeviceInfo { protected $c_devices; protected $c_active; protected $c_inactive; protected $c_offline; public function get_c_devices() { return $this->c_devices; } public function get_c_active() { return $this->c_active; } public function get_c_inactive() { return $this->c_inactive; } public function get_c_offline() { return $this->c_offline; } public function __construct($cpe_mac) { $count_device = VSE::count_device($cpe_mac); $this->c_devices = $count_device['Count_of_devices']; $this->c_active = $count_device['Count_of_active']; $this->c_inactive = $count_device['Count_of_inactive']; $this->c_offline = $count_device['Count_of_offline']; } }
The only difference is that now to get the values ββthat you would call the function instead of directly accessing these properties:
$deviceInfo = new DeviceInfo($cpe_mac); $deviceInfo->get_c_devices();
For example, it's simple, additional code may not be worth it, but it makes it easier to update this code in the future without breaking all the points that these functions call the rest of your application.