0

Sorry I'm fairly new to PHP and I'm getting this error when trying to use an argument from a function. What am I doing wrong?

public function legislatorsByZip($zip = null) {
    $url = "...";       

    $params = [
        zip => $zip,
    ];

    $data= $this->curl->simple_get($url, $params);
    return $data;
}

error:

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant zip - assumed 'zip'

Filename: models/CongressAPI.php

Line Number: 11

(zip=> $zip is line 11 btw) Please let me know if you need more info..

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
dave
  • 215
  • 3
  • 12

1 Answers1

1

use "zip" instead of zip , the assoc. array should have its keys as strings or int , words without the $ sign are constants

$params = [zip => $zip];

Change it into

$params = ["zip" => $zip];

Antoine Eskaros
  • 836
  • 5
  • 22