Get value from a array

前端 未结 2 1994
迷失自我
迷失自我 2021-01-29 12:12

update

how can I retrieve this value? I need to do that if I will write the value to my database.

array(3) {
 [1]=> NULL  

 [2]=> array(2) {

             


        
相关标签:
2条回答
  • 2021-01-29 13:04

    If your array is referenced as $myArray, you can get the string 39 via $myArray[0], i.e., this zeroth item.

    0 讨论(0)
  • 2021-01-29 13:06

    There is something missing in your output. I assume it looks something like:

    // var_dump($array);
    array(1) {
      [0]=>
      string(2) "39"
    }
    

    so you can access the value with $array[0]. Simple array access.

    As arrays are the most important data structure in PHP, you should learn how to deal with them.
    Read PHP: Arrays.

    Update:

    Regarding your update, which value do you want? You have a multidimensional array. This is what you will get:

    $array[1] // gives null
    $array[2] // gives an array
    $array[2][123] // gives the integer 123
    $array[2][122] // gives the integer 0
    $array[3] // gives null
    

    Maybe you also want (have) to loop over the inner array to get all values:

    foreach($array[2] as $key => $value) {
        // do something with $key and $value
    }
    

    As I said, read the documentation, it contains everything you need to know. Accessing arrays in PHP is not much different than in other programming languages.

    The PHP manual contains a lot of examples, it is a pretty could documentation. Use it!

    0 讨论(0)
提交回复
热议问题