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

How to match a key value in for other key value inside the same array?

I'm sorry because i know that is probably a noob question, but i have so much work to do that i cant finish my PHP learning process. Let's say i have a variable for the file extension and an array in PHP like that: $fileExt = ".php"; $mainNav =…
Luis Rivera
  • 487
  • 3
  • 12
-1
votes
1 answer

How do I reassign array positions in php?

Possible Duplicate: How to re-index the values of an array in PHP? I'm using several php functions to carry certain data over through an array, and through the process I get arrays that print_r like the following: Array ([0] => 35 [4] => 36 [6]…
Simon Suh
  • 10,599
  • 25
  • 86
  • 110
-1
votes
1 answer

Get JSON key with PHP

I have a JSON that looks like this $array = '{ "de": { "name": "last_name", "label": "Last Name", "f_type": "input" }, "en": { "name": "last_name", "label": "Last Name", "f_type": "input" …
lStoilov
  • 1,256
  • 3
  • 14
  • 30
-1
votes
1 answer

PHP, how do you change the key of an array element?

Hello guys, and Happy new year! How can I add keys to this array $my_array = array( [0] => 703683 [1] => 734972 [2] => 967385 ) So I would like to add a single key to all values example: $copy_array = array( ['id'] => 703683 ['id'] => 734972…
-1
votes
1 answer

how to change keys value from string to numeric of a multidimentional array? (codeigniter)

i have a multidimentional array. there is the details Array ( [0] => Array ( [score] => 2 [idks] => 3 [pasm] => 2 [qty] => 2 [qility] => 3 [point] => 2 [cls] => 5 [org] => 5 [outd] => 5 ) [1] => Array ( [score] => 5 [idks] => 4 [pasm] => 3 [qty] =>…
-1
votes
2 answers

php switch ($array_key) when there is no key for some array elements

I have an array. $arrayVar = array(8, 10, 'u'=>24, 'm'=>45, 54, 45); foreach($arrayVar as $curK=>$curV) switch($curK) { case 'u': echo $curK; //statement break; default: //statements …
-1
votes
2 answers

How to check if an array key value has an element

I have an array like this Array ( [0] => [ "18.06.2016", "18.06.2016", "18.06.2016", "Test Test", "Test Name", "Michael Dean", "London", "1", "980.00", "", …
adams
  • 309
  • 2
  • 17
-1
votes
3 answers

php array creation like (''=>'')

What is difference between $prefix=array(''=>''); and $prefix=array(); what exactly $prefix=array(''=>''); using for ?
-1
votes
3 answers

Multidimensional Arrays enquiry PHP

For example I have array like below: Array ( [0] => Array ( [a] => 1 [b] => 0 [c] => 1 [d] => 1 ) [1] => Array ( [a] => 2 [b] => 0 [c] => 3 [d] => 3 ) …
Gemmi
  • 1,252
  • 2
  • 13
  • 26
-1
votes
2 answers

using variable in $_POST[]

I suppose that this is very noob question but I can't figure it out. I've got code: for($i=1; $i<9; $i++){ if (isset($_POST['is'$i'ID'])) { echo $i . " is OK
"; } } And I know that the problem lies in this line : if…
wzieba
  • 414
  • 2
  • 6
  • 21
-1
votes
2 answers

Accessesing key in an array

The JSON structure below shows the format of a search result. You can get more details here { "kind": "youtube#searchResult", "etag": etag, "id": { "kind": string, "videoId": string, "channelId": string, "playlistId": string …
-1
votes
1 answer

How to compare array keys' values and insert new array elements into first array?

I've two arrays as follows: $grid_data = Array ( [0] => Array ( [newsletter_id] => 1 [newsletter_name] => Eywa Solutions [newsletter_subject] => Holi Wishes [newsletter_email_body] => Happy…
PHPLover
  • 1
  • 51
  • 158
  • 311
-2
votes
2 answers

How to display values from array vuejs

var app = new Vue({ el: '#app', data: { additionalOptions: [{ …
Jesus Erwin Suarez
  • 1,571
  • 16
  • 17
-2
votes
1 answer

Get array key does not work with Session array

I am using a Session Array on an script I designed a while back. Recently, when modifying this working script, I ran into this error: $CategoryId = key($_SESSION['StoreCategory'][$index]); Returns an error: Warning: key() expects parameter 1 to be…
user3314053
  • 239
  • 1
  • 3
  • 11
-2
votes
4 answers

foreach with key and array

I have an array with array(2) { ["bar_id"]=> array(3) { [0]=> string(1) "2" [1]=> string(1) "1" [2]=> string(1) "3" } ["foo_id"]=> array(3) { [0]=> string(2) "56" [1]=> string(2) "46" [2]=> …
benoît
  • 1,473
  • 3
  • 13
  • 31
1 2 3
10
11