1

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

2
  • I would START by looking at how you created the first array and fix that to make the array how you want it Commented Jul 10, 2018 at 14:59
  • 1
    Your code isn't actually doing anything. You're not assigning anything, modifying anything, or even outputting anything. Commented Jul 10, 2018 at 15:01

2 Answers 2

3

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?

Sign up to request clarification or add additional context in comments.

Comments

0

Because your each array has only one array You can try this code:

foreach ($unwantedArrayFormat as $upperArray) {
    $correctlyFormattedArray[] = $upperArray[0];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.