How to display an array from a database?

  • 0
    Good day. Suppose the database contains an array in the form of a key = & gt; values ​​
    'ключ1' => 'значение1','ключ2' => 'значение2','ключ3' => 'значение 3',

    I am trying to display this array, but it does not work very well, it is displayed
    Array
    (
        [0] => 'ключ1' => 'значение1','ключ2' => 'значение2','ключ3' => 'значение3',
    )

    And you need
    Array
    (
        [ключ1] => значение1
        [ключ2] => значение2
        [ключ3] => значение3
    )


    Tell me how to solve this problem. Thank you.
    MySQL Anonymous, Aug 4, 2020

  • 3 Answers
  • 0
    If someone encounters the same problem, the solution
    $result= array();
    foreach ($result_array as $row)
    {
    $result[$row['Name']]= $row['Value'];
    }



    Result
    Array
    (
    [ключ1] => значение1
    [ключ2] => значение2
    [ключ3] => значение3
    )
    Anonymous

  • 0
    Suppose an array is stored in the database as a key = & gt; values ​​
    Save it to the database as serialized data or JSON , and then convert back and no problems will be.
    Anonymous

  • 0
    print_r ($ my_array [0]);

    You're just over-nested.

    Well, or fix the code to remove the extra array, but here your code is needed or the fortuneteller of the 80th level
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!