Reputation: 63
I want to make single array from array of array. i have tried by following code but there is not output display that i want.
following is my array.
Array
(
[0] => Array
(
[0] => stdClass Object
(
[id] => 78
[user_id] => 11
[product_id] => 98
[qty] => 3
[size] => 10
)
)
[1] => Array
(
[0] => stdClass Object
(
[id] => 79
[user_id] => 11
[product_id] => 99
[qty] => 3
[size] => 10
)
)
)
And I want following type
Array
(
[0] => stdClass Object
(
[id] => 78
[user_id] => 11
[product_id] => 98
[qty] => 3
[size] => 10
)
[1] => stdClass Object
(
[id] => 79
[user_id] => 11
[product_id] => 99
[qty] => 3
[size] => 10
)
)
My code is following but it's not work
$getResult = $wpdb->get_results("SELECT * FROM mytable");
foreach ($getResult as $key => $value) {
$value->id;
}
Anyone know how to do this ? Please help me how to do this
Upvotes: 1
Views: 46
Reputation: 1073
Because your each array has only one array You can try this code:
foreach ($unwantedArrayFormat as $upperArray) {
$correctlyFormattedArray[] = $upperArray[0];
}
Upvotes: 0
Reputation: 78994
Merge the upper level arrays into one:
$result = call_user_func_array('array_merge', $array);
I don't know Wordpress, but maybe there is something other than get_results
that will return the array the way that you want it?
Upvotes: 3