top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I sort a multi-dimensional array?

0 votes
317 views
How can I sort a multi-dimensional array?
posted Jun 26, 2014 by Karamjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

By using an inbuilt function array_multisort() we can achieve

<?php
$ar = array(
       array("10", 11, 100, 100, "a"),
       array(   1,  2, "2",   3,   1)
      );
array_multisort($ar[0], SORT_ASC, SORT_STRING,
                $ar[1], SORT_NUMERIC, SORT_DESC);
var_dump($ar);
?>
answer Jun 27, 2014 by Shiva Chawala
0 votes

This can be done using the function in PHP that is called array_multisort.

For Example:

<?php $multiarray = array(array(5,4,3,2,1),array(7,8,2,9,10)); array_multisort($multiarray[0],SORT_ASC); print_r($multiarray); ?>

answer Jun 27, 2014 by Mohit Sharma
Similar Questions
0 votes
for($i=0;$i<=feof($getdata);$i++)
{
if (filter_var($data[$i][1], FILTER_VALIDATE_EMAIL)){
echo $data[$i][1];
$email=$data[$i][1];
$conn = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO promo_user (uid,name,email) VALUES (,'', '$email')";
mysqli_query($sql,$conn);
mysqli_close($conn);

I am using the above code but there is something wrong with it,whenever i run the code the echo is working fine but the content does go into sql table

Please help

...