samedi 3 mars 2018

Convert Array To Collection in Laravel

I have the following array in PHP:

[
  {
     "website": "example",
     "url": "example.com"
  },
  {
     "website": "example",
     "url": "example.com"
  }
]

Now I would like to convert this to a collection so I sort by the keys website or url. However when I do this:

$myArray = collect(websites);

I get this instead:

 {
      "0": {
         "website": "example",
         "url": "example.com"
      },
      "1": {
         "website": "example",
         "url": "example.com"
      }
    }

And the sorting does not work, I would like to know what I am doing wrong and how I can fix it so I have an array collection of objects I can easily sort.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire