WordPress.org

Ready to get started?Download WordPress

Forums

Export Arrays to .csv (1 post)

  1. mvanboordt
    Member
    Posted 1 year ago #

    Hi,

    I use the WP Export Users Plus plugin to export users to an .csv file. I'm modifying this to my needs.
    However I now come to a part where I need to export arrays.
    My arrays are build in the following way.
    Array
    (
    [key(numeral)] => value(string)
    )

    In the pluginscript the export is done with an foreach loop to get all the values out of the array.

    I want every value in the array on a separate line with an separate header.
    The plugin tells the array to output the header as the key in the database.
    The plugin also uses a sertain script to export a single value of an array but I can't seem to get this to work on my custom array's

    This is what I now have.

    if ($get_appartment) {
    		$user = get_userdata( $user->ID );
    		$unit= $user->{'appartment'};
    		$handle = fopen('php://temp', 'r+');
    
    		foreach ($unit as $appartment) {
    			   $appartment = fputcsv($handle, $unit);
    		}
    		print($appartment);
    		fclose($handle);
    }
    
    if ($get_appartment == '') { $gapp = ''; } else { $gapp = $appartment . ", "; }

    This outputs all kinds of values that I can't find in my database.

    The original script uses this to output array values:

    if ($get_user_role) { 
    
    	$user = get_userdata( $user->ID );
    	$capabilities = $user->{$wpdb->prefix . 'capabilities'};
    
    	if ( !isset( $wp_roles ) )
    		$wp_roles = new WP_Roles();
    
    	foreach ( $wp_roles->role_names as $role => $name ) {
    
    		if ( array_key_exists( $role, $capabilities ) )
    			$roleM = $role;
    	}
    
    }
    
    if ($get_user_role == '') { $gur = ''; } else { $gur = $roleM . ", "; }

    I hope somebody can help me with this.

Topic Closed

This topic has been closed to new replies.

About this Topic