0

I have an array, here is an example , and I want to get all data from (content && children). But in children I can have another (content && children) ,and so on.. If I use foreach ,I can get data just from level 1 or 2 (I don't want to use to many), so I don't get data from last level. I tried to use array_walk_recursive , but I don't get the correct data. The data from the link is from json_encode($fulljson)

    public function array_rec($item, $key)
    {
        return "$key holds $item\n";
    }
   public function handlerData(){
        Log::info('Test:' . array_walk_recursive($fulljson, 'self::array_rec'));
   }

//output will be Test: 1

1 Answer 1

0

data_get can get you data from a nested array if you know its structure.

$data = ['products' => ['desk' => ['price' => 100]]];

$price = data_get($data, 'products.desk.price');

// 100
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.