Welcome Guest, Not a member yet? Register   Sign In
Transforming query results to the proper array
#1

[eluser]Andrewkha[/eluser]
Folks hi

Sorry for the not very self-explanatory topic title. Will try to explain here what I mean.
So when querying some table I usually get a result as 2 dimensional array:

Code:
Array
(
    [0] => Array
        (
            [id] => 1
        )

    [1] => Array
        (
            [id] => 4
        )

    [2] => Array
        (
            [id] => 24
        )
)

But to pass this further as a parameter to some function I need it to be look like single dimensional:

Code:
Array
(
    [0] => 1

    [1] =>  4

    [2] => 24
)

In order to make this happen I usually use the foreach loop. But there's a feeling that there should be an easier way to do it. Any recommendations?

Code:
foreach($results as $result) {
  $query_result[] = $result['id'];
}


Messages In This Thread
Transforming query results to the proper array - by El Forum - 09-30-2014, 07:36 AM
Transforming query results to the proper array - by El Forum - 10-01-2014, 02:59 AM
Transforming query results to the proper array - by El Forum - 10-01-2014, 04:28 AM
Transforming query results to the proper array - by El Forum - 10-01-2014, 05:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB