473,497 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create 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($imageArray, array($this, 'field_name_sort'));
}
function field_name_sort(&$a, $b) {
global $field;
if ($a[???]->$field === $b[???]->$field) return 0;
return (strcmp(strtolower($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 1300

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

Similar topics

5
2950
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...
2
1920
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...
5
1548
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...
6
1800
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...
2
1305
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
2923
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...
4
1192
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...
17
1257
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...
12
1192
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...
3
1244
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
7120
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,...
0
7196
jinu1996
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...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
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...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
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 ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.