Restriction Operators :: Where - Simple 1

This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value.

function linq1()
{
    $numbers = array(5, 4, 1, 3, 9, 8, 6, 7, 2, 0);

    $lowNums = from('$n')->in($numbers)->where('$n < 5')->select('$n');

    echo 'Numbers < 5:<br />';

    foreach ($lowNums as $x)
        echo  $x.'<br />';
}

Result

4
1
3
2
0

Last edited Nov 1, 2008 at 8:52 PM by vojtechzicha, version 2

Comments

No comments yet.