0

with this function

function getCRMlist( $cmd, $order, $select, $start = 0 )
    {
        $ret = array();

        $res = CRest::call(
            $cmd,
            [
                'order' => $order,
                'select' => $select,
                'start' => (int)$start
            ]
        );

        if ( count( $res ) > 0  && 
            array_key_exists('result', $res) && 
            !empty( $res['result'] ) && 
            is_array( $res['result'] ) )
        {
            $total = (int)$res['total'];
            $ret = array();

            foreach ( $res['result'] as $key => $value ) {
                $ret[$value['ID']] = $value['TITLE'];
            }

            if ( isset( $res['next'] ) ) {
                $ret[] = getCRMlist( $cmd, $order, $select, (int)$res['next'] );
            }
        }

        return $ret;
    }

i get a result like this, with nested arrays. I want to maintain one dimension array instead. I tried several methods without accomplish the desired result with recursion. However i resolved in "pagination" way thanks to

$total = (int)$res['total'];

I would still like to know how to fix the problem through recursion. Thanks

lucalf
  • 11
  • 3
  • You need to merge the result from the recursive call, not add it as a new element. Use `$ret = $ret + getCRMlist( $cmd, $order, $select, (int)$res['next'] );` – Nick Feb 16 '20 at 23:40
  • No worries - I'm glad you got it working. – Nick Feb 17 '20 at 00:16

0 Answers0