Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

indersein's avatar

export csv in laravel with multiple array in single

Array ( [0] => stdClass Object ( [value] => [label] => Text [type] => TextInput )

[1] => stdClass Object
    (
        [value] => 
        [label] => Long Text
        [type] => LongTextInput
    )

[2] => stdClass Object
    (
        [value] => 9878427510
        [label] => Number
        [type] => NumberInput
    )

[3] => stdClass Object
    (
        [value] => 
        [label] => Select
        [type] => SelectList
    )

[4] => stdClass Object
    (
        [value] => 
        [label] => Radio
        [type] => RadioButton
    )

[5] => stdClass Object
    (
        [value] => 
        [label] => checkbox
        [type] => Checkbox
    )

[6] => stdClass Object
    (
        [value] => 
        [label] => timepicker
        [type] => TimePicker
    )

[7] => stdClass Object
    (
        [value] => 
        [label] => datepicker
        [type] => DatePicker
    )

[8] => stdClass Object
    (
        [value] => 
        [label] => date time picker
        [type] => DatetimePicker
    )

[9] => stdClass Object
    (
        [value] => 0
        [label] => rating
        [type] => Rating
    )

[10] => stdClass Object
    (
        [value] => 
        [label] => file
        [type] => FileUpload
    )

) Array ( [0] => stdClass Object ( [value] => This is testing [label] => Text [type] => TextInput )

[1] => stdClass Object
    (
        [value] => 
        [label] => Long Text
        [type] => LongTextInput
    )

[2] => stdClass Object
    (
        [value] => 9878427510
        [label] => Number
        [type] => NumberInput
    )

[3] => stdClass Object
    (
        [value] => 
        [label] => Select
        [type] => SelectList
    )

[4] => stdClass Object
    (
        [value] => 
        [label] => Radio
        [type] => RadioButton
    )

[5] => stdClass Object
    (
        [value] => 
        [label] => checkbox
        [type] => Checkbox
    )

[6] => stdClass Object
    (
        [value] => 
        [label] => timepicker
        [type] => TimePicker
    )

[7] => stdClass Object
    (
        [value] => 
        [label] => datepicker
        [type] => DatePicker
    )

[8] => stdClass Object
    (
        [value] => 
        [label] => date time picker
        [type] => DatetimePicker
    )

[9] => stdClass Object
    (
        [value] => 0
        [label] => rating
        [type] => Rating
    )

[10] => stdClass Object
    (
        [value] => 
        [label] => file
        [type] => FileUpload
    )

) Array ( [0] => stdClass Object ( [value] => This is testing [label] => Text [type] => TextInput )

[1] => stdClass Object
    (
        [value] => 
        [label] => Long Text
        [type] => LongTextInput
    )

[2] => stdClass Object
    (
        [value] => 9805376872
        [label] => Number
        [type] => NumberInput
    )

[3] => stdClass Object
    (
        [value] => 
        [label] => Select
        [type] => SelectList
    )

[4] => stdClass Object
    (
        [value] => 
        [label] => Radio
        [type] => RadioButton
    )

[5] => stdClass Object
    (
        [value] => 
        [label] => checkbox
        [type] => Checkbox
    )

[6] => stdClass Object
    (
        [value] => 
        [label] => timepicker
        [type] => TimePicker
    )

[7] => stdClass Object
    (
        [value] => 
        [label] => datepicker
        [type] => DatePicker
    )

[8] => stdClass Object
    (
        [value] => 
        [label] => date time picker
        [type] => DatetimePicker
    )

[9] => stdClass Object
    (
        [value] => 0
        [label] => rating
        [type] => Rating
    )

[10] => stdClass Object
    (
        [value] => 
        [label] => file
        [type] => FileUpload
    )

)

Hi Anyone please help me How to export multiple array in one csv file

0 likes
2 replies
drewdan's avatar

Loop through each array. implode the inner array with a comma to seperate, and write each line to a file?

tarang19's avatar

use laravel collection

for e.g.

$total = [];

            $collection = collect($total_submited_form);
            
            $collection->each(function ($item, $key) use(&$total) {
        		
    		$a['sr_no'] = $item->id;
    		$a['user_id'] = $item->user->student->fullname;
    		$a['email_id'] = $item->user->email;
    		$a['contact_number'] = $item->user->student->contact;
    		$a['Grade_Name'] = $item->grade;
    		$a['Transaction_Details'] = $item->transaction_detail;
    		$a['Transaction_Number'] = $item->transaction_number;
    		array_push($total, $a);

    	});


        return collect($total);

Please or to participate in this conversation.