2

I am new in php and i have an array like below

$sv = array(
      "my name is john", // length 15
      "i am living in london from my childwood", // length 39
      "i am 13 years old", // length 17
      "i like to become software engineer in future" // length 44
);

Now i want to try to keep highest length value on top position in my array and lowest in the bottom of the array.

and my output will be

Array
(
  [0] => i like to become software engineer in future
  [1] => i am living in london from my childwood
  [2] => i am 13 years old
  [3] => my name is john
)

If anyone can know the answer then please share it.

1

1 Answer 1

2

I think you should try

usort($sv, create_function('$a,$b','return strlen($b) - strlen($a);'));

You can get further reference from this link

How-to-sort-array-as-per-text-length-of-value?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.