Home > other >  json multiple selector in php
json multiple selector in php

Time:04-24

i have this output of json :

{
    "value": [
        {
            "vm": "vm-1060",
            "name": "node10",
            "cpu_count": 16
        },
        {
            "vm": "vm-1063",
            "name": "node2",
            "cpu_count": 16
        },
        {
            "vm": "vm-1064",
            "name": "node0",
            "cpu_count": 16
        }
    ]

and i want to list (or select) all available value's named "vm" automatically , not manual selecting ! because my json outputs are variable

CodePudding user response:

You can use next simple code:

$arr = json_decode($json, true);
$values = array_column($arr['value'], 'vm');

PHP array_column json_decode

  • Related