Commit:    bcc4cfa62ccc46113e1e47b305156caaa853723c
Author:    Hannes Magnusson <[email protected]>         Wed, 4 Dec 2013 
00:03:32 -0800
Parents:   601c8adc8f8ef057b8f55e1e511cc50d4cdadb3b
Branches:  master

Link:       
http://git.php.net/?p=web/php.git;a=commitdiff;h=bcc4cfa62ccc46113e1e47b305156caaa853723c

Log:
Fix counting logic.. as we skip an item if it doesn't exist

Also, don't allow more then 50 pics

Changed paths:
  M  images/elephpants.php


Diff:
diff --git a/images/elephpants.php b/images/elephpants.php
index 3375f9d..3cee268 100644
--- a/images/elephpants.php
+++ b/images/elephpants.php
@@ -20,7 +20,7 @@
 
 // determine how many images to serve.
 if (isset($_REQUEST['count'])) {
-    $count = intval($_REQUEST['count']);
+    $count = min(intval($_REQUEST['count']), 50);
 } else {
     header('HTTP/1.1 400', true, 400);
     print json_encode(array(
@@ -46,10 +46,11 @@ if (!$photos || !is_array($photos)) {
 // prepare requested number of elephpants at random.
 shuffle($photos);
 $elephpants = array();
-foreach ($photos as $n => $photo) {
+$got = 0;
+foreach ($photos as $photo) {
 
     // stop when we have the requested number of photos.
-    if ($n == $count || $n > 20) {
+    if ($got == $count) {
         break;
     }
 
@@ -58,6 +59,7 @@ foreach ($photos as $n => $photo) {
         continue;
     }
     
+    $got++;
     // add photo to response array.
     $elephpants[] = array(
         'title' => $photo['title'],
@@ -67,3 +69,4 @@ foreach ($photos as $n => $photo) {
 }
 
 print json_encode($elephpants);
+


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to