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
-1
votes
2 answers

array_key_exists() expects parameter 2 to be array

My Wordpress page (yarnhk.com) appears the following lines: Warning: array_key_exists() expects parameter 2 to be array, string given in /home/yarnhrnm/public_html/wp-content/plugins/fusion-core/shortcodes/class-fullwidth.php on line…
Shan Ki
  • 33
  • 1
  • 1
  • 6
-1
votes
1 answer

Parse error while using array_key_exists() method in php script

Am a newbie at PHP. I bet I am doing something silly here and hence am getting the parse error on the line where am invoking array_key_exists() function. But since am a novice at php and since the error thrown by interpreter is so abstract, I cannot…
Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
-2
votes
2 answers

"array_key_exists()" not working properly

Code $descriptionArr = array( "uk/page"=>"", "uk/page-two"=>"description of page 2"); function getDescription($uri){ if (array_key_exists($uri, $descriptionArr)) { return $descriptionArr[$uri]; } else { return false; …
skrln
  • 542
  • 2
  • 8
  • 19
-2
votes
2 answers

PHP - Searching an array

I have an Array like the following: Array ( [0] => Array ( [slideID] => 3 [parentSlideID] => 1 [subSlideOrder] => 1 [headline] => [copy] => [colourID] => 0 [URL] => 2.jpg [category] => 1 [visible] => 1 [slideOrder] => 2 [type] => 0 )…
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
-3
votes
1 answer

How to check if array index exists in go

I am coming from javascript and know how to check if a variable exists. We can use !!var I have come across an array in Go where I want to know if an index exists: myArr := []int{1, 2, 3} if myArr[3] { fmt.Println("YES") } When I run this it…
user12816097
-4
votes
1 answer

Is it safe not to use array_key_exists() when checking if an item is in the array?

I know it's possible in PHP to check if the item is in the array this way: if( my_array['item_one'] ){ # some code here... } That's because if the item isn't, then null value (that equals to false or zero) is returned instead. But will it always…
Michal
  • 43
  • 8
1 2 3 4
5