php - Apply array_values to every array field inside an object -


i have php stdclass object. inside can many fields , of them arrays. field can object can contain fields arrays on it.

the idea iterate through object , perform array_values operation when array found.

a possible object follows example:

object(stdclass)#1 (3) { ["name"]=> string(14) "i object" ["object"]=> object(stdclass)#2 (3) {   ["0"]=>   string(6) "item 1"   ["1"]=>   string(6) "item 2"   ["2"]=>   array(3) {     [0]=>     string(3) "3.1"     [1]=>     string(3) "3.2"     [2]=>     string(3) "3.3"   } } ["list"]=> array(3) {   [0]=>   string(6) "item 1"   [1]=>   string(6) "item 2"   [2]=>   string(6) "item 3" } } 

any ideas on how iterate recursively through object , apply array_values every array?

i have used function. wanted.

function rec_array_values(&$item){     if(is_object($item)){         foreach ($item $key => &$value) {             $key = rec_array_values($value);         }     }else if(is_array($item)){         foreach ($item $key => &$value) {             $key = rec_array_values($value);         }         $item = array_values($item);     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -