how i can access An array parametrs in php

Viewed 33

I have this array:

$myarr='Array(
[result] => Array
    (
        [0] => Array
            (
                [itemId] => 62751
                [fee] => 45000000
                [discount] => 0
                [netOfFee] => 45000000
            )

    )

[metadata] => Array
    (
        [isSuccessfull] => 1
        [errorMessage] => 
    ))';

I use the following code to access 'fee':

$myarr['result'][0]['fee']

And I get the following error:

Warning: Illegal string offset 'result'

Warning: Illegal string offset 'fee'

string(1) "A"

1 Answers

This is how the code should be written:

$myarr=Array(
    'result' => Array
        (
            '0' => Array
                (
                    'itemId' => 62751,
                    'fee' => 45000000,
                    'discount' => 0,
                    'netOfFee' => 45000000
                )
    
        ),
    
    'metadata' => Array
        (
            'isSuccessfull' => 1,
            'errorMessage' => 0
        ));
    
    
    echo $myarr['result'][0]['fee'];
Related