Frostillicus wrote:
"Pedro Graca" <he****@hotpop.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de... > Then, to loop through, I'm doing this:
>
> foreach ($GLOBALS['urls'] as $subarray) {
> print "\t\t<li><a
> href=\"{$subarray['href']}\">{$subarray['desc']}</a></li>\n";
> }
$subarray['href'] and $subarray['desc'] do not exist!
You may want to say this instead:
foreach ($GLOBALS['urls'][0] as $subarray) {
or
foreach ($GLOBALS['urls'] as $subarray) {
print "... {$subarray[0]['href']} ...";
}
or, better yet, review how you're using the arrays :-)
$subarray['desc'] does exist because I'm looping through $GLOBALS['urls']
quite successfully and retrieving the value for 'desc', 'href', etc for each
row in $GLOBALS['urls'] without problem.
Oops, indeed they exist. Sorry, I didn't test it.
But $GLOBALS['urls']['desc'] does not exist.
========
pedro@localhost:~$ cat xx.php
<?php
$GLOBALS['urls'] = array();
$temp['href'] = '4href: something';
$temp['desc'] = '4desc: someotherthing';
$temp['info'] = '4info: yetanotherthing';
$GLOBALS['urls'][] = $temp;
$temp['href'] = '7href: something';
$temp['desc'] = '7desc: someotherthing';
$temp['info'] = '7info: yetanotherthing';
$GLOBALS['urls'][] = $temp;
$temp['href'] = '2href: something';
$temp['desc'] = '2desc: someotherthing';
$temp['info'] = '2info: yetanotherthing';
$GLOBALS['urls'][] = $temp;
echo '$GLOBALS[\'urls\']: '; print_r($GLOBALS['urls']);
?>
pedro@localhost:~$ php xx.php
$GLOBALS['urls']: Array
(
[0] => Array
(
[href] => 4href: something
[desc] => 4desc: someotherthing
[info] => 4info: yetanotherthing
)
[1] => Array
(
[href] => 7href: something
[desc] => 7desc: someotherthing
[info] => 7info: yetanotherthing
)
[2] => Array
(
[href] => 2href: something
[desc] => 2desc: someotherthing
[info] => 2info: yetanotherthing
)
)
========
So, when you do
array_multisort($GLOBALS['urls']['desc'], ...);
PHP complains.
If I were you I'd try usort instead
function compare_desc_desc($a, $b) {
if ($a['desc'] == $b['desc']) return 0;
return $a['desc'] < $b['desc'] ? 1 : -1;
}
usort($GLOBALS['urls'], 'compare_desc_desc')
HTH
Sorry again for the mess (I got myself into).
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :