How Can I Set Up a "Where" Statement with a PHP Array

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-05-20T03:50:26Z Indexed on 2010/05/20 4:00 UTC
Read the original article Hit count: 170

Filed under:
|

Am I able to apply "where" statements to PHP arrays, similar to how I would be able to apply a "where" statement to a MySQL query?

For example, suppose I have the following array:

$recordset = array(
array('host' => 1, 'country' => 'fr', 'year' => 2010,
    'month' => 1, 'clicks' => 123, 'users' => 4),
array('host' => 1, 'country' => 'fr', 'year' => 2010,
    'month' => 2, 'clicks' => 134, 'users' => 5),
array('host' => 1, 'country' => 'fr', 'year' => 2010,
    'month' => 3, 'clicks' => 341, 'users' => 2),
array('host' => 1, 'country' => 'es', 'year' => 2010,
    'month' => 1, 'clicks' => 113, 'users' => 4),
array('host' => 1, 'country' => 'es', 'year' => 2010,
    'month' => 2, 'clicks' => 234, 'users' => 5),
array('host' => 1, 'country' => 'es', 'year' => 2010,
    'month' => 3, 'clicks' => 421, 'users' => 2),
array('host' => 1, 'country' => 'es', 'year' => 2010,
    'month' => 4, 'clicks' => 22,  'users' => 3),
array('host' => 2, 'country' => 'es', 'year' => 2010,
    'month' => 1, 'clicks' => 111, 'users' => 2),
array('host' => 2, 'country' => 'es', 'year' => 2010,
    'month' => 2, 'clicks' => 2,   'users' => 4),
array('host' => 3, 'country' => 'es', 'year' => 2010,
    'month' => 3, 'clicks' => 34,  'users' => 2),
array('host' => 3, 'country' => 'es', 'year' => 2010,
    'month' => 4, 'clicks' => 1,   'users' => 1),);

How can I limit the output to only show the keys and values related to 'host' 1 and 'country' fr?

Any help would be great.

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays