Webmaster Forums

Full Version: PHp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can i Sort Multidimensional array using PHP??
hi,

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
..........................................................................................
Web designing Chennai | Website development company Chennai | Graphic designing companies Chennai
Thank u so much for your sharing i got it
Using the following code we can sort multidimentinal array in php

<?php

// demo array to sort
$latest_array = array(
array('news','1234567890','sdf','asdpojq'),
array('news','1234567892','uruy','xbuqiwpo'),
array('comment','1234567893','fghj','mjktyu'),
array('article','1234567891','cvmo','pjklgg'),
array('news','1234567894','qwenb','asbhtyhj'),
);

$sort_field = 3; // enter the number of field to sort

// compare function
function cmpi($a, $b)
{
global $sort_field;
return strcmp($a[$sort_field], $b[$sort_field]);
}

// do the array sorting
usort($latest_array, 'cmpi');

// demo output
echo '<pre>';
print_r($latest_array);
echo '</pre>';

?>
PHP is a powerful tool for making dynamic and interactive Web pages.

PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

In our PHP tutorial you will learn about PHP, and how to execute scripts on your server.
___________________________________
Whey Protein
Protein Supplements
PHP identify how to evaluate two numbers or two text strings, but in a multidimensional array, each element is an array. PHP provides many utility to sort an array.
Hi,
Once the PHP array can store all information (strings, numbers, objects, arrays, boolean). We use an array to save the text (string). Tables store data using a key - on a subscription basis. Key is the place we saved the text string. The value is the actual text that we want to keep.
Thanks.
Reference URL's