0

Is there a way to get the values of a JSON object member variable from a array without looping the objects? Similar to how call_user_func_array would work but for member variables?

E.g.

     array   0 => 
     object(stdClass)[402]
       public 'id' => int 196
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   1 => 
     object(stdClass)[403]
       public 'id' => int 197
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   2 => 
     object(stdClass)[404]
       public 'id' => int 3269
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   3 => 
     object(stdClass)[405]
       public 'id' => int 3334
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   4 => 
     object(stdClass)[406]
       public 'id' => int 5831
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   5 => 
     object(stdClass)[379]
       public 'id' => int 6358
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0   6 => 
     object(stdClass)[400]
       public 'id' => int 6592
       public 'creditLimit' => string '0' (length=1)
       public 'state' => int 0

In one single call I'm trying to obtain the summation of creditLimit.

1 Answer 1

1

Pass "true" to json_decode to get a regular array.

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

1 Comment

Damn!!! Perfect :- array_sum(array_pluck('creditLimit', json_decode($this->_getParam('creditLimits'), true)))

Your Answer

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