Jump to content

Ordering an array by another array?


RJP1

Recommended Posts

Hi guys,

 

I'm trying to modify a Joomla listings directory component to have a sorting capability on category pages that list listings. A bit like eBay, price high to low etc.

 

The basic code that outputs each listing is as follows...

 

foreach ($this->links AS $link) {
	$fields = $this->fields[$link->link_id];
	include $this->loadTemplate('sub_listingSummary.tpl.php');
}

 

I have so far been able to get the contents of an extra field into an array within this foreach loop like this:

 

$sleeps_array = array();
foreach ($this->links AS $link) {
	$fields = $this->fields[$link->link_id];

	$sleeps = $fields->getFieldById(51);
	if(!is_null($sleeps) && $sleeps->hasValue()){
	$sleeps = $sleeps->getOutput(1);
	$sleeps_array[] = $sleeps;
	}
	include $this->loadTemplate('sub_listingSummary.tpl.php');
  	}
sort($sleeps_array);
foreach ($sleeps_array as $key => $val) {
    echo "sleeps_array[" . $key . "] = " . $val . "\n";
}

 

I've got this far but simply adding the include file to the new loop for "sleeps" does not work. I think I need to some how link the 2 arrays so that I can sort listings by the custom field... Can anyone point me in the correct direction?

 

Thanks! RJP1

Link to comment
https://forums.phpfreaks.com/topic/211211-ordering-an-array-by-another-array/
Share on other sites

I did this:

var_export($sleeps_array);

var_export($this->links);

 

For the first $sleeps_array I got:

array ( 0 => '6', 1 => '4', 2 => '2', )

 

For the second array (the one which looks like has all the listing data - and also looks "cut off"):

array ( 0 => stdClass::__set_state(array( 'link_id' => '6',

 

Thanks for the help! RJP1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.