Questions tagged [array-key-exists]

PHP function that checks if the given key or index exists in the array

The array_key_exists() checks if the given key or index exists in the array.

<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "1";
}
?>

The output will be

1

66 questions
0
votes
1 answer

array_key_exsists not working as expected PHP

Hi i am using array_key_exists in php , here is my code $action_array = array( 'add_post_ajax'=>'posts' ); if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo $_POST['action']; if(array_key_exists($_POST['action'],$action_array)) …
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
0
votes
1 answer

PHP - array_count_values or array_key_exists

Which of these two methods (array_count_values or array_key_exists) is more 'friendly' with regard to memory consumption, resource usage and ease of code processing. And is the difference big enough to where a significant performance bump or loss…
Dean Olsen
  • 131
  • 4
  • 13
0
votes
1 answer

PHP check existance of negative index not working?

I have some code that runs fine until it hits this: if(array_key_exists($snIdx, $fields)); $surnameField = trim($fields[$snIdx]); or other version I tried: if(isset($fields[$snIdx)); $surnameField = trim($fields[$snIdx]); The $snIdx =…
Joe
  • 2,551
  • 6
  • 38
  • 60
0
votes
3 answers

How To Regex Search and Replace array_key_exists with isset?

Whats the best way to do a regex search and replace for all instances of array_key_exists() with the more efficient isset()? Please, no Donald Knuth quotes regarding optimizations and yes, I'm aware of the differences between the two functions. This…
AndrewD
  • 4,924
  • 3
  • 30
  • 32
0
votes
1 answer

Constructing multidimensional array in php

I need to construct this array: Array( [Creativo] => Array( [C1] => Array( [0] => O10 [1] => O11 ) [C2] => Array( [0] => O12 [1] => O13 [2] => O14 ) ) [Detallista] => Array( …
0
votes
2 answers

Only show items containing certain keys in Multidimentional array

This is the array. Array ( [0] => Array ( [position] => TMDL [name] => Bills, Buffalo [id] => 0251 [team] => BUF ) …
Kustom
  • 181
  • 3
  • 15
0
votes
1 answer

Hash Style Array to Compare 2 Arrays

I like to compare an array from a database against another array to generate a new array of missing ids using isset or array_key_exists. Here is the array from my database I am creating. foreach ($listings as $listing) { …
Tim
  • 403
  • 1
  • 6
  • 20
0
votes
3 answers

How to properly use array_key_exists

$array = json_decode('[{"1234567":1368356071},{"7654321":1368356071}, etc, etc]'); $array2 = array(array(1234567 => time()), array(7654321 => time())); foreach($array2 as $key){ if(!array_key_exists(key($key),$array)) …
GameDevGuru
  • 1,095
  • 2
  • 12
  • 27
0
votes
1 answer

How can I solve the warning "Warning: array_key_exists."?

I'm using Hybridauth social login, and upon a user authenticating with Facebook, I receive the following error: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in …
gray
  • 798
  • 18
  • 31
0
votes
1 answer

function array_key_exists in an array that contain subb_arrays

I met some trouble with a function. In fact I would like to include all my pages, but the thing is that not all pages are named like the param $_GET['page'] for example if I call index.php?p=accueil it will redirect to php/home.php an other example…
Stanislas Piotrowski
  • 2,595
  • 10
  • 40
  • 59
0
votes
1 answer

Search multidimensional array with array_key_exists not working

I and trying to have an if else() statement look for 2 or more conditions before executing but its not working for me.. My ultimate goal for example is to search for array[Pack] and if [Type] == s45 && [packageA1] exist then to use array_slice to…
user616
  • 783
  • 4
  • 18
  • 44
0
votes
2 answers

Find the match among the same keys in an multi-nested array?

Following up this question, I have a further problem - I have two same sub keys, but they have different combination of array in their variant key, for instance, Array ( [1] => Array ( [b] => Array ( …
Run
  • 54,938
  • 169
  • 450
  • 748
-1
votes
2 answers

PHP - How to check array key exists when key include decimal place?

I was wondering whether it would be okay for some assistance in understanding why array_key_exists doesn't find my key when it's using decimal places? $value) { if…
lky
  • 1,081
  • 3
  • 15
  • 31
-1
votes
1 answer

If array key exists return its value

I have an array called all_teams which contains the following Array ( [33448] => Team1 [33466] => Team2 [33467] => Team3 [33476] => Team4 [33495] => Team5 ) I do a check within a foreach to check if teamId is in the array keys.…
CIB
  • 535
  • 1
  • 12
  • 35
-1
votes
3 answers

Pattern Output, stuck

Pretty new to all this, but here i go... I need to make 2 patterns using a table (without borders) and for-loops: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 I did work this one out with (probably not the easiest way tho, but it…
Emielh
  • 9
  • 1