将对象添加到PHP数组

I'm trying to add an object while I'm declaring an array in PHP but I can't figure out the right syntax. Here's what i'm trying:

 $obr = [
    ["Office", "Orders", { role: "style" } ],       
    ["Jacksonville", 1254, "magenta"],
    ["Orlando", 653, "blue"],
    ["Sarasota", 789, "green"],
    ["Stuart", 468, "yellow"],
    ["Tampa", 982, "cyan"]
];

Replace { role: "style" } with (object)[role => "style"]. This will cast an associative array to stdClass

You are declaring an array, if you want to add another array inside the first one, try something like this:

$obj = array(
  array("Office", "Orders", array("role" => "style")),       
  array("Jacksonville", 1254, "magenta"),
  array("Orlando", 653, "blue"),
  array("Sarasota", 789, "green"),
  array("Stuart", 468, "yellow"),
  array("Tampa", 982, "cyan"));

You've posted JSON notation of an object (JavaScript).

PHP language uses another syntax:

$obj = array(
     array("Office", "Orders", array("role" => "style")),       
     array("Jacksonville", 1254, "magenta"),
     // ...
);

or (I prefer this one as more flexible)

$obj = array();
$obj[] = array("Office", "Orders", array("role" => "style"));
$obj[] = array("Jacksonville", 1254, "magenta");
// ...

(When array is defined, you can use print_r($obj); to dump it and see its total structure.)