jmr3460 Posted January 31, 2010 Share Posted January 31, 2010 Hello All, I am developing a download counter. The only thing I am not sure why the array_key_exists() stops after the first false or first key that does not return true. The manual says: "array_key_exists() returns TRUE if the given key is set in the array. key can be any value possible for an array index." I have moved my array values around and if my $_GET link is ?id=whicheverfirst it works. Here is my php: <?php session_start(); ini_set ("display_errors", "1"); error_reporting(E_ALL); include('in_db.php'); $database = ''; $needle = $_GET['id']; $ip = $_SERVER['REMOTE_ADDR']; $date = date("Y-m-d G:i:s", time()+3600); $download_array = array('minutes' => 'minutes.pdf', 'meetings' => 'meetings.pdf'); if(array_key_exists($needle, $download_array)){ foreach($download_array as $key => $value){ if($needle == $key){ header("Location: http://www.web.org/downloads/".$value); exit(); } else { exit(); } } } ?> Can anyone tell me why it stops after the first false? Thanks Link to comment https://forums.phpfreaks.com/topic/190451-array_key_exist/ Share on other sites More sharing options...
jmr3460 Posted January 31, 2010 Author Share Posted January 31, 2010 I found it. The else statement in the if of the foreach loop was stopping it. Thanks for looking. Link to comment https://forums.phpfreaks.com/topic/190451-array_key_exist/#findComment-1004644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.