Skip to content
Advertisement

How to Get Data from this PHP Array? [closed]

JavaScript

How to get data from this array of only [type] => 102?

Advertisement

Answer

Simple and easy-to-understand solution could be as next.

The main idea – find index of required type and then retrieve data from this index.

Once you’ve find your type you will catch the index and break the loop:

JavaScript

With catched index you can easy get rest of data:

JavaScript

Outputs:

JavaScript

All in one function could be present like:

JavaScript

Outputs:

JavaScript

Demo

NOTE: This solution works properly in case of unique type value. Multiple appearances don’t supports.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement