D
D
Dmitry2014-05-26 12:11:05
PHP
Dmitry, 2014-05-26 12:11:05

How to order a PHP array?

Hello!
I can't figure out how to sort an array, by string?
I have an array like this:

array(1) {
  ["items"]=>
  array(1) {
    ["nodes:item"]=>
    array(34) {
      [0]=>
      array(2) {
        ["attribute:id"]=>
        string(5) "80857"
        ["node:value"]=>
        string(8) "Z3 (E36)"
      }
      [1]=>
      array(2) {
        ["attribute:id"]=>
        string(6) "125135"
        ["node:value"]=>
        string(7) "1 (E81)"
      }
      [2]=>
      array(2) {
        ["attribute:id"]=>
        string(6) "125024"
        ["node:value"]=>
        string(7) "1 (E87)"
      }
      [3]=>
      array(2) {
        ["attribute:id"]=>
        string(6) "125646"
        ["node:value"]=>
        string(13) "1 Coupe (E82)"
      }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nazar Mokrinsky, 2014-05-26
@nazarpc

You can use usort by passing a closure with the comparison you want.
It is not at all clear which string is being discussed from the question, but in general the task is solved in this way.

I
Ilya Lesnykh, 2014-05-26
@Aliance

What means

order array, by string
? Do you mean sorting by the node:value field?
usort

A
Alexey Kuleshov, 2014-05-26
@GingerbreadMSK

Aaaaa ... Finally, some kind of stuffing ...)))
Functions for working with arrays

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question