Why swears on syntax?

<?php error_reporting(-1); ini_set('display_errors', 'On'); mb_internal_encoding('utf-8'); function getData(){ $data = [{ "firstName": "Иван", "lastName": "Иванов", "address": "г.Москва, ул. Алиева,2", "phoneNumber": "812 143-2534" }, { "firstName": "Вася", "lastName": "Пупкин", "address": "г.Воронеж, ул. Пушкина,11", "phoneNumber": "812 123-1234" }, { "firstName": "Сергей", "lastName": "Попов", "address": "г.Пермь, ул. Савина,30", "phoneNumber": "812 321-1444" }]; return $data; } 

    2 answers 2

    $ data need to take quotes like this

      $data = '[{....}]'; 
    • Then the file_get_contents pastebin.com/r9Zmrda0 function does not work - DivMan
    • And what would it work if file_get_contents works with files. $ data is already JSON, json_decod enough. i.e. $ decode = json_decode (getdata ()); - Alexey Shatrov
    • Here primerchik nakidal sandbox.onlinephpfunctions.com/code/… - Alexey Shatrov

    PHP object syntax:

     $obj = new stdObject(); $obj->name = "Nick"; $obj->surname = "Doe"; $obj->age = 20; $obj->adresse = null; 

    PHP array syntax:

     $array = array( 1 => "a", "1" => "b", 1.5 => "c", true => "d", );