How to access a PHP array with keys of inner values

Yonatan Nir

I got a PHP array which looks like that:

array(3) {
  [0] => array(3) {
    ["Row"] => string(1) "1"
    ["Col"] => string(1) "1"
    ["Value"] => string(4) "lbl1"
  }
  [1] => array(3) {
    ["Row"] => string(1) "2"
    ["Col"] => string(1) "1"
    ["Value"] => string(4) "lbl2"
  }
  [2] => array(3) {
    ["Row"] => string(1) "3"
    ["Col"] => string(1) "1"
    ["Value"] => string(4) "lbl3"
  }
}

I know that every pair "Row" and "Col" is different from the others. I can't change the way I'm creating the array.

Can I somehow access the array kinda like a hash table like this: arr[Row => 0][Col => 0] and get the value which is in Row 0 and Col 0?

D4V1D

If I understand your question well, you would need to reformat you array in order to access it like so: $array[1][1] to get Value of lbl1.

Try this where $array is your initial Array.

<?php

$return = array();
foreach($array as $value)
    $return[$value['Row']][$value['Col']] = $value['Value'];    

var_dump($return[1][1]); // outputs "lbl1"

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to separate keys of duplicate values in an array

분류에서Dev

PHP How to sum values of the array of the same key

분류에서Dev

need to access 3 values in a php array that contains 20, is a 3d array and I need to access the same values 60 times

분류에서Dev

How do I access an object's keys' values? Looking to populate a table from object data

분류에서Dev

Array results are not displayed when I am accessing the array,How can I access specific field values in this array

분류에서Dev

Combine array form set of values and keys

분류에서Dev

Access the element inner html and attribute values inside controller function

분류에서Dev

How can I efficiently store pressed keys values in an array with SDL2?

분류에서Dev

how to sum up all values with same keys in an object inside an array and get their average

분류에서Dev

Convert array of keys-value pairs: keys for values, and values for unique keys

분류에서Dev

How to iterate through values in an array containing arrays in PHP

분류에서Dev

How to add multiple values to dictionary keys in Python

분류에서Dev

How can I set multiple default values in an HTML select control using the values in a PHP array?

분류에서Dev

How to access a var with "-" in PHP

분류에서Dev

How to access attributes of php object inside a array of php objects from javascript

분류에서Dev

how do I set keys for JSONObjects in PHP

분류에서Dev

How to access a property in array of objects without looping through all of them in php?

분류에서Dev

Php merge duplicate array values in a multidimensional array php

분류에서Dev

How to add additional values in to array

분류에서Dev

How to set array of step values

분류에서Dev

How to get values of a JSON array?

분류에서Dev

How to return same values of the array

분류에서Dev

Accessing a PHP array object(stdClass) values

분류에서Dev

Push values to the same index of an array in PHP

분류에서Dev

Programmatically replace values' presentation in PHP array

분류에서Dev

Compare array values with same key in PHP

분류에서Dev

PHP delete values from Session Array

분류에서Dev

PHP multidimensional array sort matching values

분류에서Dev

How to separate an Array in PHP

Related 관련 기사

  1. 1

    How to separate keys of duplicate values in an array

  2. 2

    PHP How to sum values of the array of the same key

  3. 3

    need to access 3 values in a php array that contains 20, is a 3d array and I need to access the same values 60 times

  4. 4

    How do I access an object's keys' values? Looking to populate a table from object data

  5. 5

    Array results are not displayed when I am accessing the array,How can I access specific field values in this array

  6. 6

    Combine array form set of values and keys

  7. 7

    Access the element inner html and attribute values inside controller function

  8. 8

    How can I efficiently store pressed keys values in an array with SDL2?

  9. 9

    how to sum up all values with same keys in an object inside an array and get their average

  10. 10

    Convert array of keys-value pairs: keys for values, and values for unique keys

  11. 11

    How to iterate through values in an array containing arrays in PHP

  12. 12

    How to add multiple values to dictionary keys in Python

  13. 13

    How can I set multiple default values in an HTML select control using the values in a PHP array?

  14. 14

    How to access a var with "-" in PHP

  15. 15

    How to access attributes of php object inside a array of php objects from javascript

  16. 16

    how do I set keys for JSONObjects in PHP

  17. 17

    How to access a property in array of objects without looping through all of them in php?

  18. 18

    Php merge duplicate array values in a multidimensional array php

  19. 19

    How to add additional values in to array

  20. 20

    How to set array of step values

  21. 21

    How to get values of a JSON array?

  22. 22

    How to return same values of the array

  23. 23

    Accessing a PHP array object(stdClass) values

  24. 24

    Push values to the same index of an array in PHP

  25. 25

    Programmatically replace values' presentation in PHP array

  26. 26

    Compare array values with same key in PHP

  27. 27

    PHP delete values from Session Array

  28. 28

    PHP multidimensional array sort matching values

  29. 29

    How to separate an Array in PHP

뜨겁다태그

보관