Note that there are some explanatory texts on larger screens.

plurals
  1. POparse php array and choose item based on condition
    primarykey
    data
    text
    <p>I am retrieving album photos from facebook's graph api. <br /> This code does the trick, however i am trying to select the <strong>smallest thumbnail that equal 130 and above width:130 x height:130</strong> <br /></p> <p>meaning the width OR height has to be 130 and above, NOT the sum of width and height.<br /><br /> <strong>note:</strong> the array list are image variation from facebooks album, so they would be in proportion. so if it is a portrait or landscape dimension it would scale in dimension accordingly.</p> <p>So from the <code>print_r</code> below you can see the in the first array, item (2) fits that description, but the other arrays would be numbers (2) and (1) since this is the smallest above 130 width/height<br /></p> <pre><code>$userURL2 = "https://graph.facebook.com/$albumID/photos?access_token=" . $fb_oAuth_token; $ch2 = curl_init($userURL2); curl_setopt($ch2, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); $data2 = curl_exec($ch2); curl_close($ch2); $pictures = json_decode($data2, true); print_r($pictures); </code></pre> <p>output from <code>print_r($pictures);</code></p> <pre><code>Array ( [0] =&gt; Array ( [height] =&gt; 288 [width] =&gt; 460 [source] =&gt; https://myurl.jpg ) [1] =&gt; Array ( [height] =&gt; 200 [width] =&gt; 320 [source] =&gt; https://myurl.jpg ) [2] =&gt; Array ( [height] =&gt; 130 [width] =&gt; 180 [source] =&gt; https://myurl.jpg ) [3] =&gt; Array ( [height] =&gt; 81 [width] =&gt; 130 [source] =&gt; https://myurl.jpg ) ) Array ( [0] =&gt; Array ( [height] =&gt; 500 [width] =&gt; 500 [source] =&gt; https://myurl.jpg ) [1] =&gt; Array ( [height] =&gt; 500 [width] =&gt; 500 [source] =&gt; https://myurl.jpg ) [2] =&gt; Array ( [height] =&gt; 480 [width] =&gt; 480 [source] =&gt; https://myurl.jpg ) ) Array ( [0] =&gt; Array ( [height] =&gt; 335 [width] =&gt; 300 [source] =&gt; https://myurl.jpg ) [1] =&gt; Array ( [height] =&gt; 335 [width] =&gt; 300 [source] =&gt; https://myurl.jpg ) ) </code></pre> <p><strong>question</strong>: How would i write this in php?</p> <pre><code>foreach($pictures['data'] as $picture){ $width = $picture['width']; $height = $picture['height']; // choose the smallest [source] above width:130 x height:130 } </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.
 

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