Best approach for filtering a multi-dimensional resultset array

Hi all,

I’ve just started using PHP with Oracle and am trying to work out the most efficient way to tackle a problem. I’ve been looking at the various PHP array functions but it’s going over my head a bit.

I’m using the Oracle driver to return multiple results from a table. The table has 5 columns. If I print_r the output of the array it looks like this:

[php]Array
(
[0] => Array
(
[PF_SEQNO] => 102
[AVG_QOS] => 4.5
[AVG_CONTACT] => 4
[AVG_COST] => 4
[COUNT] => 4
)

[1] => Array
    (
        [PF_SEQNO] => 108
        [AVG_QOS] => 3
        [AVG_CONTACT] => 3
        [AVG_COST] => 3
        [COUNT] => 1
    )

[2] => Array
    (
        [PF_SEQNO] => 125
        [AVG_QOS] => 4.5
        [AVG_CONTACT] => 4.25
        [AVG_COST] => 4.25
        [COUNT] => 4
    )

[3] => Array
    (
        [PF_SEQNO] => 125
        [AVG_QOS] => 5
        [AVG_CONTACT] => 3
        [AVG_COST] => 4
        [COUNT] => 1
    )

)[/php]

You can see there are three records, and two of them have a PF_SEQNO value of 125.

I want to filter the array to return a subset which only contains the two records where PF_SEQNO == 125.

I tried using array_filter but I can’t specify a variable and the 125 needs to change. I tried using “use” but I still don’t see how to filter against the particular PF_SEQNO key.

Another possibly alternative: is there any way to replace the [0], [1], [2] in the first level of the array with my PF_SEQNO values so I can just filter those?

At the moment I just use a for loop to find the records I want, but I’m conscious this must be highly inefficient.

Help please!!

If you know the requirement for the sql statement, use a where and group by clauses respectively. That combined with prepared statements should do what you are asking.

What he said…

SELECT column name1, columnname2 FROM yourtablename WHERE PF_SEQNO=125;

Simple as that. Forget alternatives, this is how you get the specific data. (Using prepared statements of course)

Sponsor our Newsletter | Privacy Policy | Terms of Service