I am calling an API an receiving the following object response:
+"284": "Khaki's with Black polo shirt (no logo)"
+"286": "Black pants with Yellow shirt"
+"349": "Black pants with white collared shirt"
+"705": "See "Details" Section for Dress Attire"
I want to convert this object to an associative array but I am having some trouble.
Here's what I want:
[
0 => ["id" => "284", "name" => "Khaki's with Black polo shirt (no logo)"],
1 => ["id" => "286", "name" => "Black pants with Yellow shirt"],
2 => ["id" => "349", "name" => "Black pants with white collared shirt"],
3 => ["id" => "705", "name" => "See "Details" Section for Dress Attire"]
]
Or even this:
[
"284" => "Khaki's with Black polo shirt (no logo)"
"286" => "Black pants with Yellow shirt"
"349" => "Black pants with white collared shirt"
"705" => "See "Details" Section for Dress Attire"
]
Either of these are acceptable to me.
I am trying to do collect($response->result->attire)->toArray()
but that obviously just gives me a list of names:
array:4 [
0 => "Khaki's with Black polo shirt (no logo)"
1 => "Black pants with Yellow shirt"
2 => "Black pants with white collared shirt"
3 => "See "Details" Section for Dress Attire"
]
I've tried using mapWithKeys
unsuccessfully.
Any help is greatly appreciated.