Jump to content

array_key_exist


jmr3460

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.