Question

I've an SQL query as follows:

SELECT test_user_user_id FROM OCN.tests_users WHERE test_user_test_id = 99
$this->mDb->Query( $sql );
$students_data = $this->mDb->FetchArray();

I get the array as follows:

Array
(
    [0] => Array
        (
            [test_user_user_id] => b9e6493f9f8599bc5a0a5935275228c2
        )

    [1] => Array
        (
            [test_user_user_id] => 395599c5891c1418357e2efa89bc3e27
        )

    [2] => Array
        (
            [test_user_user_id] => 3255605bb9fd3ecc0295a1bfb3cba147
        )

    [3] => Array
        (
            [test_user_user_id] => ebe6711fc156b2cc1a33f64f3d86150f
        )

    [4] => Array
        (
            [test_user_user_id] => 627b9c3f21d93f1e13af076cff20b143
        )

    [5] => Array
        (
            [test_user_user_id] => 030e96561c01afde1c46384f57cf8749
        )

    [6] => Array
        (
            [test_user_user_id] => 9def02e6337b888d6dbe5617a172c18d
        )
)

Actually I want the array in following format:

Array
    (

                [0] => b9e6493f9f8599bc5a0a5935275228c2

                [1] => 395599c5891c1418357e2efa89bc3e27

                [2] => 3255605bb9fd3ecc0295a1bfb3cba147

                [3] => ebe6711fc156b2cc1a33f64f3d86150f

                [4] => 627b9c3f21d93f1e13af076cff20b143

                [5] => 030e96561c01afde1c46384f57cf8749

                [6] => 9def02e6337b888d6dbe5617a172c18d

    )

How to get the array in above format?

Was it helpful?

Solution

$resArray = Array();
foreach($myArr as $_arr)
{
   $resArray[] = $_arr['test_user_user_id'];
}

OTHER TIPS

You could use array_map:

function user_id($e)
{
    return $e['test_user_user_id'];
}

$students_data = array_map('user_id', $students_data);
$new_array = array();
$counter = 0; // optional... because by default starting index is 0... however if you want to change the index then use a counter
foreach($students_data as $row) {
    $new_array[$counter] = $row['test_user_user_id'];
    $counter++;
}
print_r($new_array);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top