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

PHP check if array key equals to specific string value

I have an array and I want to check if the key equals to a specific string, so I can use that information and give a new value to another variable $x, depending on which key is given. So far I tried if (array_key_exists('slot1', $logoImages2)) {}…
strayed soul
  • 67
  • 1
  • 7
0
votes
2 answers

Returning multidimensional array key from selected option in PHP

I'm roughly new in PHP and I'm trying to display the contents of a multidimensional array in a table that was inside a select option list which has been selected by the user. What I'm trying to do is that the array key of the selected option is…
0
votes
4 answers

Custom sorting keys in array using self-created alphabet

In python, I have the following which works perfectly well: list = [('wr', ['A1']), ('wr-qA', ['A3']), ('wr,w', ['A4']), ('wr-mw', ['A2']), ('wrs', ['A6']), ('wrD', ['A8']), ('wrS', ['A7']), ('wr.w', ['A5']), ('=k', ['A10']), ('Dd',…
Preys
  • 121
  • 2
  • 6
0
votes
4 answers

explode an array and add array keys

I have a string that looks like this, IT, MEDIA, ADVERTISING I am then doing the following code. $criteria = explode(",", $string); This obviously creates the following when print_r is run over the $criteria. array([0] => IT, [1] => MEDIA, [2]…
Udders
  • 259
  • 5
  • 16
0
votes
2 answers

Vue: How to use variable as array key in component binding

How can I use variable array keys for bindings in my custom component? In the following example, title must be 'Title 1 for default settings' if componenttype is set to 'default', 'Title 1 for guest settings' if componenttype is set to 'guest' etc.…
Dong3000
  • 566
  • 2
  • 7
  • 24
0
votes
1 answer

How to count number keys in array which have the same name

For a flat file blog system, i have some txt files in a direcory data/articles. A txt file looks like this: id_20200430223049 // id Friends // category uploads/mainimage_5eab357970b0d.jpeg //…
john
  • 1,263
  • 5
  • 18
0
votes
1 answer

search inside arrays with condition in php

I have an api with a list of arrays inside one array and each array inside this array it has one key [attributes] and inside this key one array with key [CITY_NAME] this is my array coming from api this array number is 0 but every day this number is…
iphone acc
  • 15
  • 1
  • 4
0
votes
1 answer

Create PHP Array Dynamically

I want to create a PHP array with the following result. The array values will be passed dynamically. array( __( 'Bedroom', "my-text-domain" ) => 'Bedroom', __( 'Luxury', "my-text-domain" ) => 'Luxury', __( 'Modern', "my-text-domain" )…
Ramesh
  • 2,297
  • 2
  • 20
  • 42
0
votes
2 answers

How can i get the parent key and value if i already have children value of an array?

I am unable to figure out how to get the parent key and value with the help of it's child's key value of multidimensional array. I have an array in the format like this: [91] => Array ( [description] => Charged [boundingPoly] =>…
Neeraj Kumar
  • 506
  • 1
  • 8
  • 19
0
votes
2 answers

How to get values of array element from key

following is my array Array( [id] => 1 [user_id] => 30 [list] => Array ( [0] => Array ( [id] => 1 [card_id] => 6 [amount] => 400 ) [1] => Array …
sangRam
  • 315
  • 4
  • 17
0
votes
1 answer

Get the order item Id in WooCommerce order items

With WooCommerce, I am trying to change the download URLs for order items. Originally I was using the order ID but that only allows one subscription per order. So I need the customer to be able to purchase more than one subscription. Here is the…
ggntc
  • 57
  • 1
  • 9
0
votes
2 answers

How can I find the array key from second array where the inner keys and values match first array?

I have Array #1 which contains: Array ( [attribute_pa_color] => blue [attribute_pa_size] => large ) I have Array #2 which contains: Array ( [4624] => Array ( [attribute_pa_color] => blue …
bigdaveygeorge
  • 947
  • 2
  • 12
  • 32
0
votes
5 answers

PHP (array_keys) function not return all indexes except some keys in for loop

I'm trying to get indexes(keys) from the unsorted array but something I'm doing wrong. This is my two arrays: $unsorted = [1,2,1,14,3,1,3,6,1,13,83,4, 4 ,68]; $sorted = [83,68,14,13,6,4,4,3,3,2,1,1,1,1]; I tried the array_keys().The below code is…
Aroon
  • 991
  • 2
  • 15
  • 34
0
votes
2 answers

How to remove/replace certain characters from both keys and values in an array?

My goal is to remove a group of characters from a one dimensional array's keys and another group of characters from that same array's values. Example: $arr = [ 'a' => 'Letter A!', '`b`' => 'Letter B w/quotes...', ' c ' => 'Letter C…
CPHPython
  • 12,379
  • 5
  • 59
  • 71
0
votes
2 answers

Why isn't php explode extracting array values

I have some date values (each with a trailing = sign) stored as a &-delimited string. My $_POST['dates'] string looks like this: 23.08.18=&22.08.18=&21.08.18= I'm trying the following PHP code to extract the dates before inserting them into my…
objelland
  • 109
  • 1
  • 1
  • 9