I've been getting better at arrays but I got stumped. Ok pretty much I have an array as such.
[PHP]$row[0]
[0] =>why
[1] =>boo
[2] =>120
$row[1]
[0] =>etc
[1] =>hello
[2] =>12
$row[2]
[0] =>straw
[1] =>grape
[2] =>20
$row[3]
[0] =>apple
[1] =>orange
[2] =>30[/PHP]
so im using this:
[PHP]function cmp($a, $b)
{
return strcmp($a[2], $b[2]);
}
usort($row, "cmp");
while (list($key, $value) = each($row)) {
echo "\$row[$key]: " . $value[2] . "\n";
}
[/PHP]
and it semiworks, i think. except I get something like.
[PHP]
$row[0]
[0] =>etc
[1] =>hello
[2] =>12
$row[1]
[0] =>why
[1] =>boo
[2] =>120
$row[2]
[0] =>straw
[1] =>grape
[2] =>20
$row[3]
[0] =>apple
[1] =>orange
[2] =>30[/PHP]
When obviously I want something more like natsort, i think. pretty much:
[PHP]
$row[0]
[0] =>etc
[1] =>hello
[2] =>12
$row[1]
[0] =>straw
[1] =>grape
[2] =>20
$row[2]
[0] =>apple
[1] =>orange
[2] =>30
$row[3]
[0] =>why
[1] =>boo
[2] =>120[/PHP]
Any help plz?
12 1086
Check this out:
http://www.php.net/manual/ru/function.sort.php#13839
There are at least 2 ways sorting multidimentional array. Try to implement those solutions by yourself or ask questions according to the code.
Wow! that worked beautifully thanx for the reference.
Wow! that worked beautifully thanx for the reference.
You are welcome.
php.net is the site number one for php programmers.
You are welcome.
php.net is the site number one for php programmers.
Really?!
This is news to me!
php.net is the site number one for php programmers.
TheScripts is where it's at :P
Useful link, thanks for that satas.
TheScripts is where it's at :P
Useful link, thanks for that satas.
So at the Scripts they can show you the relevant chapters in the PHP documentation!
Ronald
TheScripts is where it's at :P
Would you be so kind to explain me what does this means?
TheScripts is where it's at :P
I guess i get it :)
(trying to get my english better)
Well, i don't agree. When you have php-related query, first of all you should have a look at the documentation (php.net in that case) And after that ask community questions. As for me it sounds like "Argh, it is so boring to spend hours reading the manual, writing the code... maybe someone could do it instead of me?" Wrong way, i think.
I guess i get it :)
(trying to get my english better)
Well, i don't agree. When you have php-related query, first of all you should have a look at the documentation (php.net in that case) And after that ask community questions. As for me it sounds like "Argh, it is so boring to spend hours reading the manual, writing the code... maybe someone could do it instead of me?" Wrong way, i think.
People will do what they do and normally that's not to get sidetracked in reading but to get fist deep in practical.
Plus, if people read the manual, what help would i be?
People will do what they do and normally that's not to get sidetracked in reading but to get fist deep in practical.
Plus, if people read the manual, what help would i be?
Manual was written by people and for people.
You'll become good programmer as fast as you'll start thinking about the problem, not asking someone to solve it.
Don't know who the author, but i like it :
' Ever tried? Ever failed? Try again. Fail again. Fail better'
Manual was written by people and for people.
Really? I thought it was aliens!
A lot of people just start programming by downloading some code, trying to change it and, when it does not go the way they want it, come to this forum. They just lack the necessary theory and general knowledge. That is why I point a lot of people to the standard public documentation for PHP and MySQL.
See my signature.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul Kirby |
last post by:
Hello All
I am trying to update me code to use arrays to store a group of information
and I have come up with a problem sorting the multiple array :(
Array trying to sort: (7 arrays put into...
|
by: Eclectic |
last post by:
Hey all,
I have been using usort to sort my multi dimensional arrays ...
function cmp($a, $b){
if($a == $b){
return 0;
}
return ($a < $b) ? -1 : 1;
}
|
by: ip4ram |
last post by:
I used to work with C and have a set of libraries which allocate
multi-dimensional arrays(2 and 3) with single malloc call.
data_type **myarray
=...
|
by: Robert P. |
last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 )
If I try storing a multi-dimensional array in the viewstate it's crapping
out on me when it goes to serialize the array (not...
|
by: JC |
last post by:
Hi all,
I have scoured the internet for articles on sorting multi-dimensional
arrays of generic types e.g. T using the IComparer<Tinterface
and have run into a real roadblack. There does not...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |