Questions tagged [array-key]

array-key refers to key portion of array holding key and value pair. In PHP array_keys() returns the keys, numeric and string, from the input array.

array-key() refers to key portion of array holding key and value pair. In PHP array_keys() returns the keys, numeric and string, from the input array.

array array_keys ( array $array [, mixed $search_value [, bool $strict = FALSE ]] )

array_keys() — Return all the keys or a subset of the keys of an array

Example:

$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));

Result:

Array
(
    [0] => 0
    [1] => color
)

Array
(
    [0] => 0
    [1] => 3
    [2] => 4
)

Reference

155 questions
0
votes
1 answer

PHP Display Array with Array_Slice

$array = array( 'name' => 'john', 'age' => '25', 'birthday' => '02-03-1988', 'gender' => 'male', 'telephone' => '98676878', 'location' => 'Australia' ); $array_slice = array_slice($array, 0, 3); foreach($array_slice as $key =>…
Ajie Kurniyawan
  • 393
  • 2
  • 18
0
votes
2 answers

Change array key from string to integer value with the array values still intact.

i am retrieving result as array from the database using codeigniter like this: Array([name]=>TempName [hobby]=>Programming) and i would like to change the above array like this: Array([0]=>Tempname [1]=>Programming) i would like to change the…
Mohammed Sufian
  • 1,743
  • 6
  • 35
  • 62
0
votes
2 answers

How to match the array keys and insert the values in new array?

I've an array called $transaction_count as follows: Array ( [0] => Array ( [transaction_status] => success [StatusCount] => 25 ) [1] => Array ( [transaction_status] => inprocess …
PHPLover
  • 1
  • 51
  • 158
  • 311
0
votes
3 answers

PHP i can't figure out how to find the array key of current parent array?

I have an assoc. multidimensional array and a function: // input: $array = array(); $array['keyname0'] = array( 'key0' => 'value0', 'key1' => 'value1', //etc, ); $array['keyname1'] = array( 'key0' => 'value0', 'key1' => 'value1', …
Michael Hurley
  • 121
  • 1
  • 5
0
votes
3 answers

How to get the keys from array

I am using GCM(Google could messaging) for the very first time and i am stuck with some problem. Although the problem has nothing to do with the GCM.I have a JSON…
Let me see
  • 5,063
  • 9
  • 34
  • 47
0
votes
1 answer

PHP Object manupulation

Hi friends. Below is an stdClass. I'm trying to parse the response, however it isn't working. I'm trying to access the object using $od[0]->FlightSegment->ArrivalAirportCode seems not working. stdClass Object ( [FlightSegment] => Array …
Radhakrishna Rayidi
  • 510
  • 2
  • 9
  • 24
0
votes
2 answers

PHP: php and .html file separation

I'm currently working on separating HTML & PHP code here's my code which is currently working for me. code.php
Detention
  • 167
  • 1
  • 1
  • 10
0
votes
2 answers

PHP: searching id tags @ .html file

I have this simple code I want to search some tags on a .html file but I get some error I'm just new to php and I encounter 'preg_match' command. here's my simple code:
Detention
  • 167
  • 1
  • 1
  • 10
0
votes
2 answers

How to get max number from array key matching a pattern

I have an array $_images['image[1]'] = image1.jpg $_images['image[2]'] = image2.jpg $_images['image[3]'] = image3.jpg $_images['image[4]'] = image4.jpg How do I find the max number/ count in the key is 4 which matches a pattern image[]. Appreciate…
Samosa
  • 845
  • 7
  • 19
0
votes
1 answer

Array keys get lost as they are considered numeric

Let's say there exists an array: $array = array( '1001' => 'a', '1002' => 'b', '1003' => 'c', ); Now let's say someone wants reverse that array: $array = array_reverse($array); The problem is, that array_reverse seems to cast all…
lampshade
  • 2,470
  • 3
  • 36
  • 74
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
3 answers

PHP - get a KEY of a nested array

I have an array called $plugins that looks something like this : Array ( [path/to/file.php] => Array ( [Name] => somevalue_a [TextDomain] => somevalue_b [value_c] => somevalue_c [value_d]…
Obmerk Kronen
  • 15,619
  • 16
  • 66
  • 105
0
votes
1 answer

Select values from an array by array of keys

I have two arrays of the same length containing some values. $a = array("a","b","x","x"); $b = array("f","g","g","h"); Now I want to get the values from $b at the index postions from where $a is x. $ids = array_keys($a, 'x'); $res =…
jakob-r
  • 6,824
  • 3
  • 29
  • 47
0
votes
3 answers

PHP Replace multidimensional array keys

I would like to replace some keys, my array is: Array ( [0] => Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 [5] => test6 ) …
Syl
  • 2,232
  • 8
  • 34
  • 45
0
votes
3 answers

PHP, how to get the Array Key in Single Dimensional Array.

In PHP I create an array of key value pairs like this, how to I get "mykey"? $arr = array("mykey"=>"myvalue"); I know the code below will work, but I am interested to know if there is a language construct in PHP that allows me to this in a easier…
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118