how to check if all elements on subvalue of array is equal to a value
<pre><code>Array
(
    [0] =&gt; Array
        (
            [id] =&gt; 10
            [on] =&gt; 2
        )

    [1] =&gt; Array
        (
            [id] =&gt; 15
            [on] =&gt; 2
        )

    [2] =&gt; Array
        (
            [id] =&gt; 20
            [on] =&gt; 2
        )

)
</code></pre>

<p>I would like the following:</p>

<ol>
<li><p>if <code>[on]=&gt;2</code> on all the sub-array,  return <strong>$result = 2</strong> </p></li>
<li><p>if one of the sub-array has <code>[on]=&gt;1</code>, return <strong>$result = 1</strong></p></li>
</ol>

<p>Can anyone help me? Thanks!</p>

<p>Have tried this, but it doesn't correct for the 1st requirment</p>

<pre><code>foreach($arr as $key=&gt;$val){

    if(in_array(2, $val)){

        $result =  2;

    }else if(in_array(1, $val)){

        $result =  1;

    }

}
</code></pre>
