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

Why is the value of array key not getting updated?

I have an array called $test_data, and I want to update a key ['test_duration']. However, I am unable to do this update. Consider the following array: Array ( [0] => Array ( [test_id] => 1116 [test_name] => ques…
PHPLover
  • 1
  • 51
  • 158
  • 311
-2
votes
2 answers

PHP assign one array's values as a keys to another array's values if both arrays keys matches

'; $directnames = array("LN"=>"ListingId","LAG"=>"AgentCode","ST"=>"MlsStatus","LP"=>"ListPrice","PIC"=>"PhotosCount"); $result =…
Neocortex
  • 653
  • 9
  • 32
-3
votes
1 answer

PHP - change/adding numerical value to array key value using submit button

I am using array to limit the results from glob(), like a pagination $show = array(5,10,15,20); $directories = glob(__DIR__.'/*', GLOB_ONLYDIR); $directories = array_slice($directories, 0, $show[0]); // shows first 5 folders How can I add value of…
FUNDIY
  • 1
  • 2
-3
votes
2 answers

How to set all values to false in array?

I have a code like this: $iterator = 0; while (($end = $sth->fetch()) && $iterator < 2) { $api_arr["data"]['tc'][] = $end["tc"]; $api_arr["data"]['em'][] = $end["em"]; $api_arr["data"]['sg'][] = $end["sg"]; $iterator ++; } I'm…
stack
  • 10,280
  • 19
  • 65
  • 117
-4
votes
3 answers

echo and add array keys

My Array: 'red', 'lemon'=>'yellow'); ?> I need to know how to echo the value of apple, so it echos "red". Also I need to know how to add a new value with php code: $fruitcolors[] = "Pear" => "Green"; etc.
Matthew Jones
  • 971
  • 1
  • 7
  • 6
1 2 3
10
11