Home > OS >  How to convert Object Array to specific attribute value array in php
How to convert Object Array to specific attribute value array in php

Time:03-09

I want to convert from this array

[{"tagid":"422"},{"tagid":"467"},{"tagid":"146"},{"tagid":"097"}] 

to

["422","467","146","097"]

Is there a way to convert this without using loop in php, or the best possible method in php?

CodePudding user response:

$json = '[{"tagid":"422"},{"tagid":"467"},{"tagid":"146"},{"tagid":"097"}]';

$arr = array_column(json_decode($json, true), 'tagid');
  • Related