I have the nested array of data below which comes from the Wordpress Formidable Pro plugin form entries database table. I would like to reformat it so I can use it in a Wordpress WP_list_table but I can't work out how to alter the innermost nested array. I need each row to be formatted like 'product_id' => '4080',
Array (
[30] => Array (
[user_id] => 2
[product_id] => 4080
)
[31] => Array (
[user_id] => 5
[product_id] => 2942
)
[32] => Array (
[user_id] => 4
[product_id] => 9630
)
[33] => Array (
[user_id] => 3
[product_id] => 2542
)
[34] => Array (
[user_id] => 7
[product_id] => 1234
)
)
The code used to produce the array:
global $wpdb;
//Retrieve the bids from the database.
$form_entries = $wpdb->get_results('SELECT * FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id in (145,147)');
$data = array();
foreach ( $form_entries as $meta ) {
if ( ! isset($data[$meta->item_id])){
$data[$meta->item_id] = array();
}
$data[$meta->item_id][] = $meta->meta_value;
}
//rename the array keys
foreach( $data as &$new_values ) {
$new_values['user_id'] = $new_values[0]; unset( $new_values[0] );
$new_values['product_id'] = $new_values[1]; unset( $new_values[1] );
}
unset($new_values);
}
I have tried messing around with strReplace and implode() but I don't really know what I'm doing. I'd be grateful if anyone could help.
Desired array:
Array (
[30] => Array (
'user_id' => '2',
'product_id' => '4080',
)
[31] => Array (
'user_id' => '5',
'product_id' => '2942',
)...