473,614 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

usort(), $GLOBALS, global keywords, php, array-of-objects, HELP!

I am having to sort an array of objects by an arbitrary object field
name that you are not going to know in advance, therefore, I cannot
name the sorting function accordingly nor reference the object
accordingly:

class ResizeView extends View {

function displayHTML() {

$field = $safe->getField();
global $field;
$safe = null;
if (!$field) $field = 'image_name'; // DEFAULT FIELD NAME

usort($imageArr ay, array($this, 'field_name_sor t'));
}
function field_name_sort (&$a, $b) {
global $field;
if ($a[???]->$field === $b[???]->$field) return 0;
return (strcmp(strtolo wer($a[???]->$field),
strtolower($b->$field));
}

}

I am stuck. I can't pass the value of $field, which is required for
the sorting to be dynamically possible according to the value of
$field within the array of objects who happens to have an object
property named the value of $field. How then can I sort my array of
objects? The PHP manual offers no help for this at all since it
doesn't involve anything LIKE this!

Thanx
Phil
Jul 17 '05 #1
0 1309

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2963
by: Alan Little | last post by:
I wrote a sorting function to use with usort(). It worked fine, and I went on with the development of my code. At one point I changed the name of the sorting function, but forgot to update it in the usort() call. Yet, it still was working. I removed the usort() call to make sure my data didn't just happen to be arriving in sorted order, and it wasn't. When I removed the usort() call, the code broke; when I put it back, it worked. I...
2
1939
by: Brian Kendig | last post by:
The server I'm running my PHP on has "magic_quotes" turned on, so all the input I get (from GET, POST, and cookies) is escaped with backslashes. I don't want this (I handle my own escaping, and I need to be able to work with unescaped strings), but I'm not allowed to change the setting on the server, so I need to figure out a way to "undo" magic quotes. This code itself works... function stripslashes_array($v) {
5
1566
by: James Tauber | last post by:
Had a question from a colleague that I embarrassingly couldn't answer. He has a script, foo.py with a global. He wants to import bar.py and needs that global available in bar.py The following obviously doesn't work: # foo.py my_global = "hello" print globals().keys()
6
1806
by: Madhusudan Singh | last post by:
Hi I am relatively new to Python. I am using Qt Designer to create a UI for a measurement application that I use. Everything seems to be clear but the use of globals (defined in the module that is generated using pyuic, that contains the form class).
2
1312
by: www.douglassdavis.com | last post by:
For example, if I put this code in a file called globaltest.php: $new_var="This is a string"; class TestClass { function __construct() { global $new_var;
18
2937
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you have a local identical variable name and want to save/load it to/from the global with same name * while you add code, the definition of globals moves more and more apart from their use cases -> weirdness; programmers thinking is fragmented * using...
4
1202
by: frizzle | last post by:
Hi there, I have a center-file index.php in it various files are included: inc/config.php, inc/functions.php in config.php $pagetitle is declared. if i call Header(), located in functions.php, it builds the header part: <html> thrue to <body> (by including header.php) the pagetitle is reffered to as $GLOBALS and that works.
17
1270
by: meridian | last post by:
I thought I had 'got' globals but this one seems strange. I want my example function 'doIt' to use and optionally modify a module variable 'gname', so I declare 'global gname' in the function, but when modified it doesn't stay modified. gname = 'Sue' def doIt(name = gname): global gname gname = name print 'doIt name', name, 'gname', gname
12
1204
by: alf | last post by:
Hi, executing main.py reulsts in following: $ python main.py Traceback (most recent call last): File "main.py", line 4, in ? amodule.f() File "/raid/home/andy/amodule.py", line 3, in f print a
3
1251
by: youngord | last post by:
<?php $mix=array( array("A",10), array("B",5), array("C",100) ); function com($x,$y){ echo $x; } usort($mix,'com');
0
8197
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.