Get Array Path as string by php - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, June 18, 2022

Get Array Path as string by php

I have arrays like this

$InternetGatewayDevice['DeviceInfo'][0]['SoftwareVersion'][1]['_value']

and also like this

$InternetGatewayDevice['DeviceInfo'][1]['SoftwareVersion'][2]['_value']

actually, both of them return same value, which is the software version for the router, but because routers belong to different vendors, I have that problem, so actually, I want to know the path that I have to go in, in order to get my value so I want to have somethings like this

InternetGatewayDevice.DeviceInfo.0.SoftwareVersion.1._value

as a string I mean I want a function where I can provide to it the array and the key ,so the function will return to me the path of the array that I have to follow in order to get the value like this

getpath($array,"SoftwareVersion")

whhich will return value like this

InternetGatewayDevice.DeviceInfo.0.SoftwareVersion

are there any way to do this in php ?or laravel package or is there any way in PHP to get the value whatever the number key is? I mean like this

$InternetGatewayDevice['DeviceInfo'][*]['SoftwareVersion'][*]

so what ever the key it will return the value



source https://stackoverflow.com/questions/72660450/get-array-path-as-string-by-php

No comments:

Post a Comment