Foreach loop inside array

后端 未结 3 1542
灰色年华
灰色年华 2020-11-27 06:02

I\'m trying to create an array inside an array, using a for loop - here\'s my code:

    array(
    \'label\' => \'Assign to user\',
    \'desc\' => \'C         


        
3条回答
  •  时光取名叫无心
    2020-11-27 06:03

    That's invalid syntax. You'd have to build the "parent" portions of the array first. THEN add in the sub-array stuff with the foreach loop:

    $foo = array(
        'label' => 'Assign to user',
        'desc' => 'Choose a user',
        'id' => $prefix.'client',
        'type' => 'radio',
        'options' => array()
    );
    
    foreach ($clients as $user) {
        $foo['options'][] = array (  
            'label' => $user->user_login,  
            'value' => $user->user_login,
        );
    }
    

提交回复
热议问题