Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe this may work for you. It will return the smallest pic that satisfies the min width/height or false if none of the pictures satisfy.</p> <pre><code>$test = array( 0 =&gt; array( 'height' =&gt; 288, 'width' =&gt; 460, 'source' =&gt; 'https://myurl.jpg' ), 1 =&gt; array( 'height' =&gt; 81, 'width' =&gt; 130, 'source' =&gt; 'https://myurl.jpg' ), 2 =&gt; array( 'height' =&gt; 200, 'width' =&gt; 320, 'source' =&gt; 'https://myurl.jpg' ), 3 =&gt; array( 'height' =&gt; 130, 'width' =&gt; 180, 'source' =&gt; 'https://myurl.jpg' ), 4 =&gt; array( 'height' =&gt; 100, 'width' =&gt; 120, 'source' =&gt; 'https://myur5.jpg' ) ); $pic = getTheRightPic($test, 130, 130); var_dump($pic); function getTheRightPic($pictures, $min_width, $min_height) { //get one to start with do { $win_pic = array_pop($pictures); } while ( ! checkXY($win_pic, $min_width, $min_height)); //if none of the pic satisfies return false if ($win_pic === false) { return false; } foreach ($pictures as $pic) { $win_pic = comparePics($win_pic, $pic, $min_width, $min_height); } return $win_pic; } function comparePics($original, $compare, $min_width, $min_height) { if ( ! checkXY($compare, $min_width, $min_height)) { return $original; } //calculate sizes $original['size'] = $original['width'] * $original['height']; $compare['size'] = $compare['width'] * $compare['height']; //return the smaler pic if ($original['size'] &gt; $compare['size']) { return $compare; } return $original; } function checkXY($pic, $min_width, $min_height) { if ($pic['width'] &lt; $min_width &amp;&amp; $pic['height'] &lt; $min_height) { return false; } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload