Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Retrieve value from associative array-error

hello

i had stumbled on kinda simple problem but i can’t get and idea what could be wrong:

        function zabbixGraphGetId($HostName, $Name,$zabbixData) {

            try {

                $api = new ZabbixApi(...$zabbixData);

            } catch (Exception $e) {
                // Exception in ZabbixApi catched
                echo $e->getMessage();
            }
            $GetGraphId = $api->graphGet(array(
                'output' => 'extend',
                'filter' => array('host' => $HostName),
                'search' => array('name' => $Name)
            ));
            $ReturnGraphId = $GetGraphId['0']->graphid;

            return $ReturnGraphId;
        }

Thats my function in symfony and i want to get from array $GetGraphId value of only graphid. Point is after i call this function i get this error: Warning: Attempt to read property "graphid" on array
But if i’ll return whole array($GetGraphId) i get this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

array:2 [
  0 => array:19 [
    "graphid" => "some id"
    "name" => "Network traffic on tun0"
    "width" => "900"
    "height" => "200"
    "yaxismin" => "0"
    "yaxismax" => "100"
    "templateid" => "0"
    "show_work_period" => "1"
    "show_triggers" => "1"
    "graphtype" => "0"
    "show_legend" => "1"
    "show_3d" => "0"
    "percent_left" => "0"
    "percent_right" => "0"
    "ymin_type" => "1"
    "ymax_type" => "0"
    "ymin_itemid" => "0"
    "ymax_itemid" => "0"
    "flags" => "4"
  ]

so there is graphid value yet i still cant get it, i would really appreciate any clues/ideas/solutions
thanks!

>Solution :

The warning says it: Attempt to read property "graphid" on array. You cannot access graphid with object->property notation. Use this line instead:

$ReturnGraphId = $GetGraphId['0']['graphid']; 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading