Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to replace string array KEY to numbers according to array length in php?

I have a PHP array as below :

Array
(
    [Cpu] => Cpu
    [Memory] => Memory
    [Ping] => Ping
    [Interface - Ethernet] => Interface - Ethernet
    [Disk - C:] => Disk - C:
    [Disk Reponse - C] => Disk Reponse - C
    [Top Memory] => Top Memory
    [Top Cpu] => Top Cpu
    [Process - DFSR] => Process - DFSR
    [Process - DNS] => Process - DNS
    [Process - IsmServ] => Process - IsmServ
    [Process - lsass] => Process - lsass
    [Process - svchost] => Process - svchost
    [Process] => Process
    [Interface] => Interface
    [Disk] => Disk
    [Disk Reponse] => Disk Reponse
    [Link-Discovery] => Link-Discovery
    [Microsoft Hyper-V Network Adapter #2] => Microsoft Hyper-V Network Adapter #2
    [Mellanox ConnectX-4 Lx Virtual Ethernet Adapter] => Mellanox ConnectX-4 Lx Virtual Ethernet Adapter
)

I need to replace array KEY to numbers according to array length starting from ‘0’(zero) as below ,

Array
(
    [0] => Cpu
    [1] => Memory
    [2] => Ping
)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just use array_values

array_values($array_name);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading